A little help please

Hi, i have a little problem with an object, let me explain:

i have an object called “object” that object has a touch function when i touch the background called “cielo” 

the object move to object.y - 5 and when i release the touch the object move to object.y + 5, the background has a movement in -x that simulates the movement of the object in x but my object only moves on y with the touch event, this is the code of the touch event

object = display.newImage("misil.png") object.x = 120 object.y = 160

motiony = 0 function cielo:touch(event)  if (event.phase == "began") then  speed = 5;  motiony = -speed;  elseif event.phase == "ended" then speed = 5;  motiony = speed;  end  end  cielo:addEventListener("touch",cielo)

 local function moveguy (event)  object.y = object.y + motiony;  end  Runtime:addEventListener("enterFrame", moveguy)

 the problem is not on that code, my problem is when i try to put a line behind the object like a fire that the object left behind when it moves in the map, this is the code of the line

local function line1() local myRectangle1 = display.newRect( object.x, object.y, 10, 10 ) end timerline = timer.performWithDelay(10,line1,0)

the rectangle paints it in the object.x and object.y that means when the touch event is on the myRectangle.y will be equals to +5. but the object doesnt move on x and the myRectangle1 only moves in y that is my problem i want to movement in x and y, my idea is to move the myRectangle in -x like it has movement,  because i cant move the object on x and i cant call myRectangle1 in other function because i get an error saying the object myRectangle is nil.

I hope I have expressed myself correctly because im learning englsh and im new in corona  :smiley:

Something like this, maybe?

(I tested it with y moving in a sine pattern… seemed to look okay.)

local xpos = { x = 0 } -- A proxy object for the exhaust local my\_line, prevx, prevy local X = 120 local TimePerScreen = 3000 local NumberOfScreens = 2 local FinalX = -NumberOfScreens \* display.contentWidth transition.to(xpos, { time = TimePerScreen \* NumberOfScreens, x = FinalX, iterations = -1, -- Repeat forever onRepeat = function() transition.to(my\_line, { -- Move the old line the rest of the way off screen... time = TimePerScreen, x = my\_line.x - display.contentWidth, -- onComplete = ... remove it, etc. }) my\_line = nil -- ...and start a new one. prevx = prevx - FinalX -- Correct the previous x to account for the split end }) timer.performWithDelay(10, function() local x, y = xpos.x, object.y if x == FinalX then -- x might still be a big negative value for a few frames x = 0 end if x ~= prevx or y ~= prevy then if my\_line then -- line already exists? my\_line.x = X + x my\_line:append(X, y) elseif prevx then -- previous point exists? my\_line = display.newLine(X + prevx, prevy, X, y) my\_line.strokeWidth = 3 end prevx, prevy = x, y end end, 0)

It uses lines instead of rects, and breaks them up every now and then. Having finite lines lets you use transitions, and you can clean up the lines once they’re far enough behind you.

A dummy “x position” object is used to indicate how far back to move the line.

its exacly what i want thank u so much :D:D:D:D:D! im gonna study the code because the “transition.to” is totally new for me. Like i said im new on corona but i want to learn thank you again!

Something like this, maybe?

(I tested it with y moving in a sine pattern… seemed to look okay.)

local xpos = { x = 0 } -- A proxy object for the exhaust local my\_line, prevx, prevy local X = 120 local TimePerScreen = 3000 local NumberOfScreens = 2 local FinalX = -NumberOfScreens \* display.contentWidth transition.to(xpos, { time = TimePerScreen \* NumberOfScreens, x = FinalX, iterations = -1, -- Repeat forever onRepeat = function() transition.to(my\_line, { -- Move the old line the rest of the way off screen... time = TimePerScreen, x = my\_line.x - display.contentWidth, -- onComplete = ... remove it, etc. }) my\_line = nil -- ...and start a new one. prevx = prevx - FinalX -- Correct the previous x to account for the split end }) timer.performWithDelay(10, function() local x, y = xpos.x, object.y if x == FinalX then -- x might still be a big negative value for a few frames x = 0 end if x ~= prevx or y ~= prevy then if my\_line then -- line already exists? my\_line.x = X + x my\_line:append(X, y) elseif prevx then -- previous point exists? my\_line = display.newLine(X + prevx, prevy, X, y) my\_line.strokeWidth = 3 end prevx, prevy = x, y end end, 0)

It uses lines instead of rects, and breaks them up every now and then. Having finite lines lets you use transitions, and you can clean up the lines once they’re far enough behind you.

A dummy “x position” object is used to indicate how far back to move the line.

its exacly what i want thank u so much :D:D:D:D:D! im gonna study the code because the “transition.to” is totally new for me. Like i said im new on corona but i want to learn thank you again!