Question about swapping images

HI all

If I had a number of objects moving about the screen that I wanted to change the image of when they were pressed, what would be the easiest way of doing this? I’ve looked at the “fishies” example which uses two overlayed images but would that be the best method as it seems like a cheat.

Cheers
Chris [import]uid: 7841 topic_id: 19843 reply_id: 319843[/import]

If you have sprites moving around, and they have a listener attached, you can just change the currentFrame of the sprite in the event. [import]uid: 108660 topic_id: 19843 reply_id: 77009[/import]

Cheers Jeff, I had thought of that but can’t quite seem to get my head around sprites. I’m guessing it’s really pretty easy though. Can I be cheeky and ask for quick example?? [import]uid: 7841 topic_id: 19843 reply_id: 77011[/import]

No problem:

Create a folder.
Add main.lua and any image bigger than 80 x 40. (I used buttonRed.png)

Paste this into main.lua, run it, and tap the image

local spr = require "sprite"  
tilesheet = sprite.newSpriteSheet("buttonRed.png", 30, 30)  
tileset1 = sprite.newSpriteSet(tilesheet, 1,2 )  
local function onSprite(event)  
 local t = event.target  
 t.currentFrame = 2  
end  
local mySprite = sprite.newSprite( tileset1 )  
mySprite.currentFrame = 1  
mySprite.x = display.contentWidth/2  
mySprite.y = display.contentHeight/2  
mySprite:addEventListener( "touch", onSprite )  
  

[import]uid: 108660 topic_id: 19843 reply_id: 77018[/import]

Flippin eck Jeff, that’s sooo easy!
You are an absolute legend Sir :slight_smile:

[import]uid: 7841 topic_id: 19843 reply_id: 77028[/import]