1

I am trying to make an app with QML for Ubuntu Touch that is similar to the game Avalanche, and am unsure how to go about inserting a varying number of falling blocks. All of the blocks will be the same picture, but will have different sizes and IDs. The blocks will also be deleted when they go off screen (so they don't fill up any more RAM to store their sizes, IDs, etc. when they are no longer needed). Here is the template for the blocks that I would like to use:

Image {
    id: block0 //The first block will be 0, the second 1, the third 2, and so on
    source: "block.png"
    height: units.gu(Math.floor(Math.random) * 5 + 1)
    width: height
    x: units.gu(Math.floor(Math.random() * (75 - width)))
}

So, how can I have this code snippet be written to and deleted from the QML file when the game is played? I would like to do this with JavaScript so it will be easier to make the IDs and store them in an array to easily access information. Sorry if this is difficult to understand, and thanks for the help!

  • Look at the QML samegame code. You should be able to use most of that. The only difference is size randomization, which it looks like you have figured out. – RobotHumans Jul 3 '13 at 2:25
2

You can dynamically create elements from the code. Check this out:

http://qt-project.org/wiki/QML-Dynamic-Objects

0

I have done something similar in one of my game. Simplified code is explained in following post

http://kunalmaemo.blogspot.com/2011/04/creating-qml-element-dynamically-on.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.