help for moving player , ( tricky question )

hello everyone ,

I want my player start in the middle of the screen , then when I press the screen ( background ) my player move to the Left of the screen , but during this moving if I press the screen again my player go to the left of the screen , with out waiting my player to end of his moving in first movement .

I wish you help me out for this, I can make my player when I press the screen go to ( player.x = 320 ) after he get there I can make him go back ( player.x = 320 ) .

but my point , how can I make him change his direction during his first movement .

[import]uid: 13061 topic_id: 22832 reply_id: 322832[/import]

I think your post is very confusing and contains some errors in what it is you want. If I interpret it to what I think you are trying to do I would say there’s two ways to do this.

  1. Use transition, and upon a second screentouch cancel the first transition and start a new transition.

  2. Write your own move code in an enterframe function. That would be SOMETHING like this:

[code]
local hero
local movedirection = “right”
local speed = 5 – higher means faster, lower means slower

hero = display.newImage(“hero.png”, 0,0)
hero:setReferencePoint(display.CenterReferencePoint)
hero.x = 320
hero.y = 240

local function frameLoop()
if movedirection == “right” and hero.x < 320 then
hero.x = hero.x + speed
elseif movedirection == “left” and hero.x > 20 then
hero.x = hero.x - speed
end
end – frameLoop

local function screenTouched()
if event.phase == “ended” then
if movedirection == “left” then
movedirection = “right”
else
movedirection = “left”
end
end
end – screenTouched

Runtime:addEventListener(“enterFrame”, frameLoop)
Runtime:addEventListener(“touch”, screenTouched)

I’m all for method 2 because it’s my style of coding.
p.s. I’m saying SOMETHING like this because I’m writing this from the top of my head. Try to understand the concept and write your own code - don’t expect this code to work out of the box because it’s untested. If you have any errors try to find them and fix them. If you can’t, post again.

Good luck,
Thomas [import]uid: 70134 topic_id: 22832 reply_id: 91201[/import]

thank you for the concept ,I will try to understand it and make wt I need, thank u

u wrote that u may misunderstood my question , I will make it easy ,

if I press the screen , my player go to Right , if I press it again , my player go to left , if I press it third time my player go to Right ,

but the point , not here, my point that I want to know,

in first press the screen my player go to Right is easy ,

but in second press and third , etc , I want my player change his direction during his movement not .

anyway , I will try your code , then get back to u , thank u again ,

[import]uid: 13061 topic_id: 22832 reply_id: 91320[/import]

It’s confusing because in your first post you said the tap makes him move left, but another tap makes him move left again but I think you meant right. Then later you said a tap makes him go to player.x = 320 and another tap makes him go to player.x = 320 which is the same location. Maybe you mean player.x = 0. Your second reply is a bit clearer. [import]uid: 31262 topic_id: 22832 reply_id: 91331[/import]