Changing an Image

Let me set up a scenario: Let’s say in my game I have a main character, a bunch of enemies that are constantly spawning and the main character has to shoot, and then a static background image. There is a also a score counter that increases when the main character kills an enemy. All of the characters and the background are .png images. Is it possible that when the score counter reaches a certain number, let’s say 20, that the .png images switch to a different specified image? So if the enemies had previously been pictures of aliens, when the score reaches 20, they would become pictures of monkeys. Any and all replies are very much appreciated. [import]uid: 7116 topic_id: 8039 reply_id: 308039[/import]

delete the “alien” image and load a new “monkey” image and place the monkey image in the same x,y location of the alien image after you reach num points.

if numpoints > certainMumPoints do
in my group find all the ‘alien’ images
get each alien image x,y position
delete image
load monkey image
set monkey.x and monkey. to the x,y pos of the alien image.
end

C. [import]uid: 24 topic_id: 8039 reply_id: 28676[/import]

Well that would work if I had a set number of enemies on the screen, but how would that work if new enemies were constantly being spawned? Thanks :slight_smile: [import]uid: 7116 topic_id: 8039 reply_id: 28840[/import]

put the enemies on a list and figure out a LRU algorithm [import]uid: 24 topic_id: 8039 reply_id: 28847[/import]

why not use a sprite sheet and just switch sprites when you need to. Only display one frame. Just call the sprite:prepare(“monkey”) and sprite:play() when you want to switch it?

Maybe? [import]uid: 10361 topic_id: 8039 reply_id: 28866[/import]

put the enemies on a list and figure out a LRU algorithm

I don’t know what an LRU algorithm is but yeah you’ll want to stick all your enemies in a table and then loop through that table whenever you want to change all of them. [import]uid: 12108 topic_id: 8039 reply_id: 29207[/import]

LRU - least recently used

http://en.wikipedia.org/wiki/Cache_algorithms

c
[import]uid: 24 topic_id: 8039 reply_id: 29516[/import]