How do I Create Frame Independent Functions

Get help using Construct 2

Post » Fri Apr 15, 2016 4:18 pm

I have a function that runs and goes through hundreds of sprites ... every time that happens the game freezes for few seconds, the results dont need to effect the objects immediately every frame.

How do i make this frame independent ?
B
6
S
2
Posts: 8
Reputation: 458

Post » Fri Apr 15, 2016 4:38 pm

A function, like a loop will be executed on a single tick.

Do you need your loop to go through all the elements.
If for example you are looping through each instances of an object type and want to do a specific action on a specific instance, once you found it, use the stop loop action, it will prevent from looping through the rest of instances which we know are wrong/not the one you are looking for and can allow you to freeze your application less.

If you want to not freeze the execution, yet still, each tick analyse through a bunch of the instances (but enough that you don't feel the freeze), it depends in great part on your project's code, but you could increment the value of a global variable each tick, and use this value to pick an instance (through its IID possibly ?) and analyse only this instance through a specific event.
Still a "loop", but which execution goes over several frames of execution.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Fri Apr 15, 2016 4:50 pm

I see, so only way of doing this is still in one frame but you instead divide the entire process into several frames, ... there is a point in my game when the number of instances can be even up to few thousands.

I guess i set a global variable that will designate how many of the objects i will go through each frame with IIDs and each frame i will check for my conditions. And depending on the CPU load i can have an other function that will check the variable to dial down the number of IIDs checked / frame ...

That would in essence create the frame independence ... Thank you :)
B
6
S
2
Posts: 8
Reputation: 458


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest