I’m trying to change an image when it is dragged, but so far doesn’t seem to be working.
Here’s what I have
local image1 = display.newImage("image1.png")
image1.x = 50; image.y = 50
local function startDrag( event )
local t = event.target
t.x = event.x
t.y = event.y
replaceImage()
end
local function replaceImage()
if (event.target == image1) then
image1 = "image2.png"
end
end
image1:addEventListener( "touch", startDrag )
Anyone know what I’m doing wrong? I’ve tried all sorts of other options too but none seem to work. [import]uid: 40538 topic_id: 8731 reply_id: 308731[/import]
elseif event.phase == “ended” or event.phase == “cancelled” then
image2.isVisible = false
image1.isVisible = true
end
end
image1:addEventListener(“touch”, drag)
– i haven’t test this yet, but it should give you an idea. [import]uid: 12455 topic_id: 8731 reply_id: 31907[/import]
w.baig84
You can’t change the image of an object returned by display.newImage.
You may follow teex84’s good method.
Another workaround is to use Sprite. A sprite can load a long image which is composed of concatenated images. You can switch to any of these images after creation of a sprite. Hope it helps.