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 / Problem with animated sprite only showing intermittently

Author
Message
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 17th Oct 2012 01:34
I've got a piece of code that checks if an enemy has been hurt, and if it has been hurt an animated sprite is created to show stars flashing around on the enemy, moving around in a random pattern following the enemy's position.

The problem is, the animated sprite only shows up every now and then, and most often not, but I never get an errormessage for trying to manipulate a sprite that doesn't exist when I set the sprite position or delete it.

Also, I've printed the enemy[n].hurt while playing and the flag shows up correctly. The depth of the enemy sprites is 10.

Here's the code:


Is the problem that I create the sprite when it happens? I thought this would save a bit of resources instead of creating the "sparkle" sprite for each enemy beforehand and then just making it visible when I want it.

Thanks, Toby

My hovercraft is full of eels
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 17th Oct 2012 05:26
Unless you have a large number of enemies on the screen at once, I think you could just have an animated "stars" sprite follow each enemy around. Make the animation have a last frame with no pixels, so that you see nothing when the animation is done playing. That way you can just "fire and forget" - loop the animation through the stars - but if an enemy is NOT hurt, then set the animation to the blank frame.

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 17th Oct 2012 10:57
I'm not sure yet how many enemies there will be on a level, but I'm guessing no more than 20. I'll try it that way thanks

My hovercraft is full of eels

Login to post a reply

Server time is: 2024-05-04 07:08:20
Your offset time is: 2024-05-04 07:08:20