Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. [SOLVED]text output
QtWS25 Last Chance

[SOLVED]text output

Scheduled Pinned Locked Moved Game Development
9 Posts 3 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lexan
    wrote on last edited by
    #1

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

    for example

    @var answer;
    var question;
    switch(operation)
    {
    case 0:
    answer= firstVar + secondVar;
    question=firstVar +"+"+ secondVar;
    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chuck Gao
      wrote on last edited by
      #2

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

      Chuck

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lexan
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chuck Gao
          wrote on last edited by
          #4

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

          property string questionText : ""

          function xxx() {
          var answer;
          switch(operation)
          {
          case 0:
          answer = firstVar + secondVar;
          questionText = firstVar + "+" + secondVar;
          break;
          }
          }

          Image {
          .....

          Text {
          anchors.centerIn: parent // Something like this
          text: questionText // So the questionText should be a property
          }
          }

          ....
          @

          Chuck

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lexan
            wrote on last edited by
            #5

            wait Im gonna try that :D

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lexan
              wrote on last edited by
              #6

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

              this is my complete code

              @import QtQuick 1.0
              import "Logic.js" as Logic

              Rectangle{
              property string questionText:""

              function questions(r){
                  var first = Math.floor(Math.random()*11);
                  var second = Math.floor(Math.random()*11);
                  var operation = Math.floor(Math.random()*4);
              
                  var answer;
                  var question;
                  switch(operation)
                  {
                  case 0:
                      answer=first+second;
                      question=first+"+"+second;
                      break;
                  case 1:
                      answer=first-second;
                      question = first + "-" + second;
                      break;
                  case 2:
                      answer=first*second;
                      question=first+"*"+second;
                      break;
                  case 3:
                      answer=first/second;
                      question=first+"/"+second;
                      break;
                  }
              }
              

              Image{
              id:fire
              width:90;height:90
              smooth: false
              visible: false
              source: "../../../../../Users/MAJA/Desktop/lahat na/Untitled-1.png"
              fillMode: Image.PreserveAspectCrop
              Text {
              anchors.centerIn: parent
              text: questionText
              }

              ParallelAnimation{
                  running: visible
              
                  NumberAnimation{target: fire;property: "width";to:150;duration:1500}
                  NumberAnimation{target: fire;property: "height";to:150;duration: 1500}
                  NumberAnimation {target:fire;property:"y";from:0 ;to:550;duration:4500}
                  NumberAnimation{target: fire;property: "x";from: fire.x* Math.random;duration: 8500}
              
              }
              

              }

              }@

              so what's the problem here

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chuck Gao
                wrote on last edited by
                #7

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

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

                @
                Image{
                id:fire
                width:90;height:90
                smooth: false
                visible: false // When to set it true
                .....

                ParallelAnimation{
                    running: visible // use fire.visible
                

                ....
                }

                }
                @

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

                Chuck

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dialingo
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lexan
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved