The Daily Click ::. Forums ::. Klik Coding Help ::. simultaneous creation/destruction issue
 

Post Reply  Post Oekaki 
 

Posted By Message

SolarB



Registered
  26/12/2011
Points
  564
12th March, 2012 at 12/03/2012 04:32:38 -

Sorry to be posting so much, but the more progress I make with my project the more issues I find!

Right now I'm having a problem with objects being simultaneously created/destroyed. I have say 20 enemies, and a the player explodes a bomb. Each enemy's health is simultaneously reduced to 0 and they are destroyed. On each enemy's destruction +1 is added to a 'kills' counter. When this happens, only +1 is added to the counter instead of +20!! Of course, this works when run through a ForEach loop, but surely each individual object should be parsed, even if events for each occur simultaneously?

Similarly, lets say I have one "+1" active that changes animation/direction depending on the powerup picked up. So:

player overlaps powerup
->create "+1" at location of powerup
->set "+1" direction to x

If two powerups are overlapped at once, two "+1" actives are created at the right locations but sometimes one of them refuses to change its direction to match the powerup that it should!


Basic example:
http://www.mediafire.com/?vp768qxvv38ddp6



 
My Open Source Examples: http://bit.ly/YyUFUh

Windybeard Games



Registered
  14/04/2005
Points
  219

You've Been Circy'd!VIP MemberCandy Cane
12th March, 2012 at 12/03/2012 08:22:16 -

Hi Noodles. I have had the exact same issue recently. I did use resort to using a ForEach loop for every death, every item collection and so on, it took a while to add but now everything works perfectly and actually seems faster than before.

i think if you are creating multiples at exactly the same point and same time you will also need to run this through a loop, if only for effeciency sake, plus looping all this just makes it all run perfectly without any issues.

The game im making is a fast paced shmup with loads of enemies, loads of loot and lots of ForEach loops to handle it. It is very much worth using the ForEach fo this issue.

 
n/a

SolarB



Registered
  26/12/2011
Points
  564
13th March, 2012 at 13/03/2012 01:00:59 -

Thanks Windybeard, glad to know someone else has come across this. I have set it up with the extension, and the pickups work fine. However, I still get a slight pause/framerate drop when the loop for enemies is activated, say when I have 100 all exploding at once (but that could also be because each enemy leaks a ton of blood with every frame before they do so). This is worse without the extension, say:

always
--> start loop 'destroy' Nobjects 'enemy'

on 'destroy'
--> destroy 'enemy' (still works without value spreading etc. for some reason)


Do you start your ForEach loop 'Always' or on a certain condition?

 
My Open Source Examples: http://bit.ly/YyUFUh

Windybeard Games



Registered
  14/04/2005
Points
  219

You've Been Circy'd!VIP MemberCandy Cane
13th March, 2012 at 13/03/2012 20:06:46 -

using the always to start a ForEach loop is not a great idea. It is always best to start the loop when it is needed at a certain point. Plus i find that having the loop called for by the specific enemy when it is need to be most efficient. if you see what i am saying...

What i do is something like

Enemy alterable value "Health" <= 0
start ForEach loop "death" (for that enemy) 1 times

On ForEach loop "death" (for that enemy)
What ever you want to happen (including destroy)

This way i find that it will do each enemy 1 at a time whenever the call for it happens (in this case "Health <=0)

I have no idea if this is a good way of doing it but i have tested this on many computers that are much lower spec than mine and there is no difference is frame rate also this minimises the loop to only the dying enemies. In mine the mass kill is really only about 40-50 kills and each enemy drops 5-25 loot objects plus a particle effect and explosion for each enemy who dies.

The way in which i drop the enemy Health to 0 say for a nuke like attack is by having a screen flash of white, This flash has a alt variable for how much damage it does and then this value is subtracted by whatever it hits. This also gives me the option of tweaking its power plus keeping tabs on how much damage it will do to a boss which i obviously dont want killing in 1 hit.

Hope this helps.



 
n/a
   

Post Reply



 



Advertisement

Worth A Click