A
A
Alexander2015-04-15 08:26:23
Qt
Alexander, 2015-04-15 08:26:23

How many timers can be used at the same time in QML?

I decided to write a game without using the engine and I'm thinking how to implement the structure.
Let's say I have many objects of the same type (boxes) on the form that "exist on their own": Box.qml
Each object appears at the top of the form in a random place and falls down. Without physics, a simple straight-line fall, like blocks in Tetris fall.
To stop a block from falling when it hits another block or reaches the bottom of the form, I do a collision check like this: in each block (in Box.qml) a Timer is run which calls the collision check function. This function is also written in this block (Box.qml). At the same time, after a collision has occurred, the timer with checks should not stop, because the current block should continue to fall if the block on which it fell disappears.
In the main window (main.qml), the construction is something like this: the main timer creates a Box object every second and starts the fall function in it (in fact, this is also a timer, which is also written in Box.qml)
This option, it seems to me, is easy to implement, because you don’t need to create a game loop and track each object in it, because each object tracks “itself”, knows how to fall, knows when to stop, knows when to continue falling .
So far nothing has been written, I'm just thinking about how to do it more correctly and here's what worries me in my plan: there can be 50 blocks on the form, how will such a number of timers affect performance? Isn't it wasteful to use timers inside objects?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DancingOnWater, 2015-04-15
@DancingOnWater

50 timers is a sign of bad architecture.

P
Pavel K, 2015-04-17
@PavelK

Use events instead of timers. In Qml , almost everything is bound ... I don’t know how in Russian ,
google qml binding create any map for example 1111111 1002001 1000001 1111111 Where 2 is your object. 1 - wall 0 - empty space At least two-dimensional, at least three-dimensional. and then just generate an event and interact with it. Falling can be replaced with animation. But it's best not to use qml components, but to draw it all yourself. Otherwise, 50 objects and hellish brakes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question