Friday, May 3, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1166  / 2 Years ago, fri, may 13, 2022, 9:37:45

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!


More From » application-development

 Answers
2

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



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


[#30477] Sunday, May 15, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ippalogu

Total Points: 215
Total Questions: 127
Total Answers: 146

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
ippalogu questions
Tue, Jan 4, 22, 21:49, 2 Years ago
Tue, Sep 21, 21, 09:12, 3 Years ago
Wed, May 19, 21, 02:24, 3 Years ago
Mon, Dec 27, 21, 01:44, 2 Years ago
;