What is the easiest way to change multiple image depending on how many object you have?

I want to change image for every banana that I have…

so let’s say I have 1 banana the image would be a basket with one banana
when the banana count is 2 then the image would be a basket with two banana and so on…

I have created the images, but don’t know the easiest way to change them…

I currently use

basket = display.newImage(“basketWithzerobanana.png”)

function bananacheck ()
if banana == 1 then
basket = display.newImage(“basketWithonebanana.png”)
elseif banana == 2 then
basket = display.newImage(“basketWithtwobanana.png”)
end
end

Runtime:addEventListener (“enterFrame”, bananacheck)

And it doesn’t work… could someone help me? [import]uid: 117857 topic_id: 22093 reply_id: 322093[/import]

Here’s what would work better.

[lua]local banana = sprite.newSprite(sprite.newSpriteSet(sprite.newSpriteSheet(“bananas.png”, 30, 30), 1, 5)) – -- Takes a 150x30 bananas.png image and splits it into five 30x30 frames; Starts at frame 1, which is a basket with 0 bananas

local function bananacheck ()
if bananacount == 0 then
banana.currentFrame = 1 – Frame 1, which is basket with 0 bananas
elseif bananacount == 1 then
banana.currentFrame = 2 – Frame 2, which is basket with 1 banana
elseif bananacount == 2 then
banana.currentFrame = 3 – Frame 3, which is basket with 2 bananas
– Etc. Just make sure that the last argrument to the sprite sheet corresponds with the number of frames you have
end
end

Runtime:addEventListener (“enterFrame”, bananacheck)[/lua] [import]uid: 103624 topic_id: 22093 reply_id: 87768[/import]

+1 to sprite solution.

In an app I’m currently working on (kids app) the kid has to pick oranges and put them in a basket. I used a sprite sheet for this, too.

Peach :slight_smile: [import]uid: 52491 topic_id: 22093 reply_id: 87786[/import]

While the code above is pure and simple, I’m still hoping for something like display.changeImage( “file.png” ).

I’ll put it into a request, unless Peach can bring it right up to the DJ to put it into the queue. :stuck_out_tongue: [import]uid: 6084 topic_id: 22093 reply_id: 109562[/import]

Haha, sorry but the DJ isn’t working tonight :wink:

If you wouldn’t mind putting in a written request via this form then it will be in the system; http://developer.anscamobile.com/forms/support

Thanks :slight_smile: [import]uid: 52491 topic_id: 22093 reply_id: 109958[/import]