Falling Objects help



  • 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



  • 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.



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.