Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: * 5 + 1)
    width: height
    x: * (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!

share|improve this question
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
up vote 2 down vote accepted

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

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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