July 5, 2011

lexan lexan
Lab Rat
68 posts

[SOLVED]text output

 

hi everyone. I’m planning to display a question on my image that would come from a script or code…

for example

  1. var answer;
  2. var question;
  3. switch(operation)
  4. {
  5. case 0:
  6. answer= firstVar + secondVar;
  7. question=firstVar +"+"+ secondVar;
  8. break;

I need to display the question thingy on the falling objects I’m doing

how would i do that? :D
thanks for the response in advance :D

8 replies

July 5, 2011

Chuck Gao Chuck Gao
Lab Rat
342 posts

I’m sorry, but you want to use QML ? What’s your falling object ?

 Signature 

Chuck

July 5, 2011

lexan lexan
Lab Rat
68 posts

yeah im using QML right now.. falling object.. a custom image of a meteor

July 5, 2011

Chuck Gao Chuck Gao
Lab Rat
342 posts

I think that’s should not be a problem. Do i understand it right ?

  1. ....
  2.  
  3. property string questionText : ""
  4.  
  5. function xxx() {
  6.   var answer;
  7.   switch(operation)
  8.   {
  9.     case 0:
  10.     answer = firstVar + secondVar;
  11.     questionText = firstVar + "+" + secondVar;
  12.     break;
  13.   }
  14. }
  15.  
  16. Image {
  17. .....
  18.  
  19.   Text {
  20.     anchors.centerIn: parent // Something like this
  21.     text: questionText // So the questionText should be a property
  22.   }
  23. }
  24.  
  25. ....

 Signature 

Chuck

July 5, 2011

lexan lexan
Lab Rat
68 posts

wait Im gonna try that :D

July 5, 2011

lexan lexan
Lab Rat
68 posts

your code seems helpful but now the image doesn’t appear

this is my complete code

  1. import QtQuick 1.0
  2. import "Logic.js" as Logic
  3.  
  4. Rectangle{
  5.     property string questionText:""
  6.  
  7.     function questions(r){
  8.         var first = Math.floor(Math.random()*11);
  9.         var second = Math.floor(Math.random()*11);
  10.         var operation = Math.floor(Math.random()*4);
  11.  
  12.         var answer;
  13.         var question;
  14.         switch(operation)
  15.         {
  16.         case 0:
  17.             answer=first+second;
  18.             question=first+"+"+second;
  19.             break;
  20.         case 1:
  21.             answer=first-second;
  22.             question = first + "-" + second;
  23.             break;
  24.         case 2:
  25.             answer=first*second;
  26.             question=first+"*"+second;
  27.             break;
  28.         case 3:
  29.             answer=first/second;
  30.             question=first+"/"+second;
  31.             break;
  32.         }
  33.     }
  34.  
  35.  
  36. Image{
  37.     id:fire
  38.     width:90;height:90
  39.     smooth: false
  40.     visible: false
  41.     source: "../../../../../Users/MAJA/Desktop/lahat na/Untitled-1.png"
  42.     fillMode: Image.PreserveAspectCrop
  43.     Text {
  44.        anchors.centerIn: parent
  45.        text: questionText
  46.     }
  47.  
  48.     ParallelAnimation{
  49.         running: visible
  50.  
  51.         NumberAnimation{target: fire;property: "width";to:150;duration:1500}
  52.         NumberAnimation{target: fire;property: "height";to:150;duration: 1500}
  53.         NumberAnimation {target:fire;property:"y";from:0 ;to:550;duration:4500}
  54.         NumberAnimation{target: fire;property: "x";from: fire.x* Math.random;duration: 8500}
  55.  
  56.     }
  57.  
  58. }
  59.  
  60.  
  61. }

so what’s the problem here

July 5, 2011

Chuck Gao Chuck Gao
Lab Rat
342 posts

Not trying your code, but something you should make sure:

1. Your Rectangle width and height and also anchors when necessary

2.

  1. Image{
  2.     id:fire
  3.     width:90;height:90
  4.     smooth: false
  5.     visible: false  // When to set it true
  6. .....
  7.  
  8.     ParallelAnimation{
  9.         running: visible // use fire.visible
  10. ....
  11.     }
  12.  
  13. }

And a kind advice for you, when you start to write a QML app, have a look at the example and document first :-)

 Signature 

Chuck

July 5, 2011

dialingo dialingo
Lab Rat
158 posts

By the way, there are tons of wonderful examples available. Here is a directory for Qt Quick examples:
http://developer.qt.nokia.com/wiki/qml_examples_directory

July 5, 2011

lexan lexan
Lab Rat
68 posts

actually after carefully looking at my codes and modifying it.. I found the problem on my .js file so its working already. thanks for the help guys

 
  ‹‹ Display problem      [SOLVED]Question in Destroying Objects ››

You must log in to post a reply. Not a member yet? Register here!