How to change an objects appearance after touching it?

More or less how to change an object’s image into another image. I’m completely lost in this except I’m thinking I’m gonna need to put both images in the same group. Thanks again in advance! [import]uid: 35535 topic_id: 9912 reply_id: 309912[/import]

I do something like this. At work so dont know the exact code, but SOMETHING like this :stuck_out_tongue:

obj = {}  
obj.image1 = 'red.png'  
obj.image2 = 'blue.png'  
obj.imageCurrent = obj.image2  
  
obj.changeImage = function()  
 if obj.imageCurrent == obj.image1   
 then obj.imageCurrent = obj.image2   
 elseif obj.imageCurrent == obj.image2   
 then obj.imageCurrent = obj.image1   
 end  
 obj.image = display.newImage(obj.currentImage,0,0)  
end  
obj.changeImage()  

something like that…that probably wont work, you could always just pass the name of the image to the function too…

obj.changeImage = function(pic)  
obj.image = display.newImage(pic,0,0)  
end  
obj.changeImage('green.png')  

I havent tested it, ill find out what I actually use later this evening. [import]uid: 34945 topic_id: 9912 reply_id: 36175[/import]

Don’t get me wrong because I really do appreciate you putting in your time to answer me, but I’m relatively new so I don’t really understand everything. What I’m trying to do is have obj1 on the screen and when I touch it for the first time, I want it to turn into obj2. Again I have a limited understanding on what the best way to do this is but what I’m now thinking of is putting a touch listener to obj one so that once touched, obj1 will be deleted and obj2 will spawn in it’s place. What would you say?
[import]uid: 35535 topic_id: 9912 reply_id: 36187[/import]

Correct :slight_smile:
following the previous…

function obj:tap(event) self.changeImage('green.png') end obj:addEventListener( "tap", obj ) [import]uid: 34945 topic_id: 9912 reply_id: 36192[/import]