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. Falling Objects help
Forum Updated to NodeBB v4.3 + New Features

Falling Objects help

Scheduled Pinned Locked Moved Game Development
3 Posts 2 Posters 2.6k Views 1 Watching
  • 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 24 Jun 2011, 11:08 last edited by
    #1

    I have started with my game a sort of typing maniac like game. I am would like to ask some help with this.
    In this game after clicking the button, there would be falling objects with in mine, a falling fire in the screen
    but after doing some QMLing, nothing has appeared on the screen as I have intended.. Please help me out

    this is the codes for the falling object

    @Item {
    id: block

    Image {
        id: img
        anchors.fill: parent
        source: "K:/mukha/fire.png"
    }
    NumberAnimation on y {
            to: screen.height / 2
            running: created
            onRunningChanged: {
                if (running)
                    duration = (screen.height - img.y) * 10;
                else
                    state = "OffScreen"
            }
        }
    
        states: State {
            name: "OffScreen"
            StateChangeScript {
                script: { img.created = false; img.destroy() }
            }
        }
    

    }
    @

    after that this is javascript code

    @var first=1;
    var last=0;
    var total=20;
    var timeSinceLast=0;
    var speed=5;
    var posInWindow

    function startNewGame(){
    if(timeSinceLast>20){
    if(last<total){
    if(Math.random()<.1){

                last++;
                createBlock();
                timeSinceLast=0;
                if(speed<100)speed+=.5
    
            }
        }
    }
        timeSinceLast++;
    

    }

    function createBlock(){
    if (component == null)
    component = Qt.createComponent("Block.qml");

    if(component.status==Component.Ready){
        var dynamicObject = component.createObject(background);
        if(dynamicObject == null){
            console.log("error");
            console.log(component.errorString());
            return false;
        }
       // dynamicObject.type=Math.floor(Math.random()*3)
        dynamicObject.x= posInWindow.x;
        dynamicObject.y= posInWindow.y;
    
    }else{
        console.log("error");
        console.log(component.errorString());
        return false;
    }
    

    return true;
    }
    @

    and the code for the button in my main.qml

    @
    Button {
    anchors { left: parent.left; verticalCenter: parent.verticalCenter }
    text: "New Game"
    onClicked: SameGame.startNewGame()
    }@

    there are no errors shown in the application output panel so I'm kinda confuse.. please help

    1 Reply Last reply
    0
    • B Offline
      B Offline
      baysmith
      wrote on 24 Jun 2011, 20:18 last edited by
      #2

      Have you tried clicking on the Button more than 20 times? If I read the code correctly, startNewGame() is called on each click, but it only creates a block if timeSinceLast > 20.

      Nokia Certified Qt Specialist.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lexan
        wrote on 28 Jun 2011, 07:38 last edited by
        #3

        Yes I did. after 20 + times there shows an error

        1 Reply Last reply
        0

        2/3

        24 Jun 2011, 20:18

        • Login

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