can some one help me move a object

I control my hero with a d-pad and I want the enemy’s to go after him when he gets close but all I can get them to do is go to his original x and y location not his current one I am using :

   transition.to( enemy1, { time=20000, y=hero.y, x=hero.x } )
   transition.to( enemy2, { time=10000, y=hero.y, x=hero.x } )

this dose not do what I want oh and I don’t want it to be at a time just speed

how are you moving the hero

I added images of up down right left arrows and called them up, down, left, and right.  

–D-Pad–

local motionx = 0
local motiony = 0
local speed = 7

local function stop (event)

 if event.phase == “ended” then
 motionx = 0
 motiony = 0
 end
end

local function moveHero(event)

 hero.x = hero.x + motionx
 hero.y = hero.y + motiony
end

local function goingup(event)

 if event.phase == “began” then
 motionx = speed
 motiony = 0
 hero:prepare(“goup”)
 hero:play()
 end
 
end

local function goingdown(event)

 if event.phase == “began” then
 motionx = -speed
 motiony = 0
 hero:prepare(“godown”)
 hero:play()
 end
 
end

local function goingleft(event)

 if event.phase == “began” then
 motionx = 0
 motiony = -speed
 hero:prepare(“goleft”)
 hero:play()
 end
 
end

local function goingright(event)

 if event.phase == “began” then
 motionx = 0
 motiony = speed
 hero:prepare(“goright”)
 hero:play()
 end
 
end

up:addEventListener(“touch”, goingup)
down:addEventListener(“touch”, goingdown)

left:addEventListener(“touch”, goingleft)
right:addEventListener(“touch”, goingright)

Hi @mikegg21,

Just a note, I see evidence that you’re using the deprecated and older (unsupported) “sprite” library (code bits like “prepare”). This library was replaced with the newer sprite library well over a year ago, and while it may still function, it will no longer be supported. Regardless of how you accomplish the control part of this, you should convert to the new sprite methods immediately.

http://docs.coronalabs.com/guide/media/imageSheets/index.html

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best regards,

Brent Sorrentino

how are you moving the hero

I added images of up down right left arrows and called them up, down, left, and right.  

–D-Pad–

local motionx = 0
local motiony = 0
local speed = 7

local function stop (event)

 if event.phase == “ended” then
 motionx = 0
 motiony = 0
 end
end

local function moveHero(event)

 hero.x = hero.x + motionx
 hero.y = hero.y + motiony
end

local function goingup(event)

 if event.phase == “began” then
 motionx = speed
 motiony = 0
 hero:prepare(“goup”)
 hero:play()
 end
 
end

local function goingdown(event)

 if event.phase == “began” then
 motionx = -speed
 motiony = 0
 hero:prepare(“godown”)
 hero:play()
 end
 
end

local function goingleft(event)

 if event.phase == “began” then
 motionx = 0
 motiony = -speed
 hero:prepare(“goleft”)
 hero:play()
 end
 
end

local function goingright(event)

 if event.phase == “began” then
 motionx = 0
 motiony = speed
 hero:prepare(“goright”)
 hero:play()
 end
 
end

up:addEventListener(“touch”, goingup)
down:addEventListener(“touch”, goingdown)

left:addEventListener(“touch”, goingleft)
right:addEventListener(“touch”, goingright)

Hi @mikegg21,

Just a note, I see evidence that you’re using the deprecated and older (unsupported) “sprite” library (code bits like “prepare”). This library was replaced with the newer sprite library well over a year ago, and while it may still function, it will no longer be supported. Regardless of how you accomplish the control part of this, you should convert to the new sprite methods immediately.

http://docs.coronalabs.com/guide/media/imageSheets/index.html

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best regards,

Brent Sorrentino