Touch to move object to the targetted coordinate

[lua]local function playerWalk(event)
if (event.phase == “ended”) then
player.newX = event.x
player.newY = event.y
player.state = “walk”
end
end
ground:addEventListener(“touch”, playerWalk)

local function updateFrame(event)
if(player.state == “walk”) then

– Move Right
if(player.sprite.x < player.newX) then
player.sprite.xScale = 0.3

–??
– Move Left
else
player.sprite.xScale = -0.3

–??

end
end
end
Runtime:addEventListener( “enterFrame”, updateFrame )[/lua]
I want to move my object to the targetted coordinate when i touch on the background, but i dont know how to update the coordinate to let the object move at a certain speed? anyone can help? [import]uid: 40786 topic_id: 19761 reply_id: 319761[/import]

You would use transition.to() and set the time parameter based on the distance between the object and the touch.

Or are you still stuck on how to make the player move to begin with? (I might have sample code for that somewhere so let me know.)

Peach :slight_smile: [import]uid: 52491 topic_id: 19761 reply_id: 76549[/import]

i am using runtime:addEventListener(). if i use transition.to() i will be calling this function at fps. [import]uid: 40786 topic_id: 19761 reply_id: 76560[/import]

You seem to be scaling the sprite, so I’m not totally sure what you are trying to achieve.

I can see you are using a Runtime listener but I’m wondering why that is - is there a reason for it? If you only want the sprite to move on touch then a tap/touch listener on the background would be less intensive.

Peach :slight_smile: [import]uid: 52491 topic_id: 19761 reply_id: 76561[/import]

the scaling is the direction the player is facing. -0.3 is facing left and 0.3 is facing right. i using runtime enterframe because i got a parallax view and i need to move the background while the player move to a spot. [import]uid: 40786 topic_id: 19761 reply_id: 76566[/import]

I dont know if there is a better way in doing this [import]uid: 40786 topic_id: 19761 reply_id: 76568[/import]

So you are moving the background and not the actual character? (Like in a dash or endless game where it just looks like the character is moving?)

How were you planning on moving if not with transition.to? Is that your complete code related to this above? [import]uid: 52491 topic_id: 19761 reply_id: 76850[/import]