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