Hi Peach,
My code is EXACTLY that code in Corona`s Blog. To be honest, I just made one modification: I put a Variable to be sure that only one element in screen will move (strange effects without this trick):
function element:touch( event )
if event.phase == "began" then
event.target:toFront()
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
self.onlyme = true
elseif event.phase == "moved" and self.onlyme == true then
local x = (event.x - event.xStart) + self.markX
if x \< 0 then x = 0 end;
if x \> (\_W-30) then x = (\_W-30) end;
(continue the same)
This “onlyme” variable is here just to be sure only one element on the screen will move in the same time.
My program do this: Imagine 2 squares, one yellow and another one blue. I move both on the screen.
If I do a “double tap” in a color, this color tapped copy itself, so, If I do this is a blue square, now I have 2 blue squares and one yellow visible.
Imagine now that I’m dragging and dropping a blue square (or yellow) on the other. The desired effect is that both squares disappear and a new square, green, appear in place.
My problem is that it seems to drag the movement is not occurring properly with this code. It seems that the element is “tied.” I do a collision between objects only in phase “ended” of the event …
elseif event.phase == "ended" then
self.onlyme = false
element\_collide()
end
… so I suppose that this code should not interfere (element_collide) the movement of the elements on the screen.
In time, the elements are stored in a table and drag event is added when built as follows:
tabela[#tabela]:addEventListener( "tap", buttontap)
where “tabela” is a table (this remains in portuguese, my first language).
Do not bother with the #. In my code, I assure you that the element is created in the last position of the table.
When I build the program, even in simulator, the element dont seen to follow the bouse (button pressed) or my finger, in the screens.
How setFocus() helps me and I did not understand? Of course, I miss something, I dont know what…
Thanks!
[import]uid: 9133 topic_id: 21071 reply_id: 83328[/import]