Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Playing an animated lightning effect

Author
Message
JORGEMAL
14
Years of Service
User Offline
Joined: 2nd Aug 2009
Location:
Posted: 9th Sep 2012 00:23
I have an animated sprite that is a lightning effect, so I use the PlaySprite command. My situation is that, as soon as it finishes playing, the last image is kept in the screen and I would like it to disappear. I tried inserting commands to delete the image and the sprite after PlaySprite but this way nothing is seen. I will very much appreciate any comment.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 9th Sep 2012 00:30
I handle it this way:



Which essentially means I create it just before using it. And delete it when I'm done in Pirates Treasure:



Hope that helps.

JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 9th Sep 2012 03:23 Edited at: 9th Sep 2012 03:45
Would it be faster to hide the sprite after the last frame displays. Then just unhide it when you want to play it again?



I'm not sure if it would effect performance or not to delete then recreate a sprite rather then hide then un-hide?

Attachments

Login to view attachments
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 9th Sep 2012 03:48 Edited at: 9th Sep 2012 03:51
Here, I've made a quick test with an explosion animation. Just click and your mouse pointer will explode. Once the animation is over the sprite will be invisible. I do three checks in this situation;

1) Check for if there is an explosion, if not create one
2) If explosion is created play explosion sprite
3) If explosion is done reset explosion sprite

Each one is dependent on the variable exp. This is so the sprite is only effected by certain condition during each stage of it's life. I'd turn this into a function so you can call it whenever needed easily.

Hope this helps. Files attached.


Attachments

Login to view attachments
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 9th Sep 2012 04:38
That works also Josh ; I get concerned about hiding things and not freeing up memory myself?

Not sure how AppGameKit handles it though ; also theres concerns about too many calls to create and delete things depending on how frequently you use it?

My lightning bolts are not on the screen constantly so I felt the better decision was to delete it myself
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 9th Sep 2012 05:09 Edited at: 9th Sep 2012 05:10
I wouldn't think it would effect memory since the image data is already loaded? Though if it's an animated particle creating and deleting would probably work better. If it's an effect that appears only during certain conditions, then keeping it handy might help speed up the game. IDK

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 9th Sep 2012 19:20
Hiding and Showing is MUCH faster than deleting and creating.

Make the last frame of your animation as a blank frame, so when you play it once, it automatically disappears on the last frame!!!
Alien Menace
AGK Developer
19
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 15th Sep 2012 09:56 Edited at: 15th Sep 2012 09:57
You could create an additional blank animation frame then set the sprite's image to that frame number when the effect no longer needed. This way you don't have to keep hiding and showing the sprite, just play the animation when it's needed.

Apps published: 3

Login to post a reply

Server time is: 2024-05-04 08:38:03
Your offset time is: 2024-05-04 08:38:03