Windows instance_create only once (1step)

jonjons

Member
Hello everyone, I would like to know what is the best way to instatiate a peojectile instance or effect or play sound during an animation ?
I mean the best practice that people are using these days ?

Its a problem thats been haunting me, everytime from day 1 ever since i started using GM... Having an instance created in a certain animation frame, and to have that instance spawn 60 times in all 60( steps/frame per second )... having to create a variable on/off and a new case or if statment just to lock that instance from spawning multiple times... It turns the code into a mess with multiple bla bla bla variables flying around.o_O

Ive been looking again into ( animation event ) and ( animation Update ) but these are all related to spine animations.

Also i rebember watching a Heart Beast video (now lost), were he could instatiate an instance only once by fiding the correct time frame 0.05 / 2.025 etc... in an animation. And being able to change that animation speed at any time without having to change the code.

Is there a way to work with the animation itself (timeLine / timeFrame), instead of using the (60 steps) processing step event ?
 

Sybok

Member
See if it allready exists before creating it :)

Pseudo code

Code:
if(!instance_exists(some_inst))
    create_instance(...
 

jonjons

Member
thanks for the reply
but that will cause even more problems, it might be necessary to increse the number of cases or if's, making the code even more messy.
Its also a solution that has been posted multiple times in the forum

I mean a way to really handle the animation timeline with code... and stay away from the 60 steps time interations
I mean something like this: maybe a visual image explains better how the code could be handled in the correct way.

animation.png

[ edit ]
The real problem is how to get that correct ( frame 2.3872643872647 / frame 6.783643 ) time spot and being able to change the speed at ny time...
It just doesnt seem to be a way to remove this trap out of the way...
 
Last edited:

Yal

šŸ§ *penguin noises*
GMC Elder
Easiest solution: split the sprite up into before and after the frame you want stuff to spawn, then spawn the thing in the Animation End event (check the sprite; if it's the attack animation, spawn the appropriate attack and switch to the Attack Cooldown sprite; using a switch statement you can handle as many different attack animations as you want easily this way. For idle sprites, etc, that should loop, you simply do nothing here.)
 

jonjons

Member
Yes exactly "Timelines" but why isnt anyone using it on animations ?
I cant seem to find the time line in GM2 on 1.4 it seem to be in the object events if iam not mistaken
 
Top