Hello everybodies,
I would like to change an image once the user has touch the screen. My touch handler is flyUp. My image was created in the CreateScene(). I would like to do a kind of swiping image on touch event.
player = display.newImageRect("ballon.png", 150,170 ) player.anchorX = 0.5 player.anchorY = 0.5 player.x = display.contentCenterX - 450 player.y = display.contentCenterY+100 physics.addBody(player, "static", {density=0.1, bounce=0.1, friction=0.1}) screenGroup:insert(player) player.myName="player" player.isFixedRotation = true
Now, I would like to change the picture when the user clic on the screen :
player = display.newImageRect("ballon\_2.png", 150,170 ) player.anchorX = 0.5 player.anchorY = 0.5 player.x = display.contentCenterX - 450 player.y = display.contentCenterY+100 physics.addBody(player, "static", {density=0.1, bounce=0.1, friction=0.1}) screenGroup:insert(player) player.myName="player" player.isFixedRotation = true
So, i’ve tried to handle this :
function flyUp(event) if event.phase == "began" then player.bodyType = "dynamic" player:applyForce(0, -200, player.x, player.y) elseif event.phase=="ended" then player = display.newImageRect("ballon\_2.png", 150,170 ) player.anchorX = 0.5 player.anchorY = 0.5 player.x = display.contentCenterX - 450 player.y = display.contentCenterY+100 physics.addBody(player, "static", {density=0.1, bounce=0.1, friction=0.1}) screenGroup:insert(player) player.myName="player" player.isFixedRotation = true end end end
Unfortunatly, it doesn’t work. Do you have an ideal ? Thank you