Hello to everyone!
I’m coding a physics game, and i have found a frustrating behavior when use the “Drag Platforms” source code from the Sample Apps area.
When i touch (without move) a draggable object, it falls down on the scenario, but comes back to the initial position. But the more times you touch (without move) the same object, the more falls down, until it falls out of the platform.
The thing is, this only happen between dynamic objects and static objects. If i have a dynamic object above another dynamic one, it doesn’t fall. And it’s frustrating because after a few touches, the object just disappear from the scenario.
I’m trying to improve the code, stablishing the draggable object from “kinetic” (in the original code) to “static”, and nothing happens.
Another change that doesn’t works is to change the final position from the original source code, like the code following, checking if the initial and final position was changed (if not, doesn’t rest the initial position to the final one):
Original code:
[code]elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
– Switch body type back to “dynamic”, unless we’ve marked this sprite as a platform
if ( not event.target.isPlatform ) then
event.target.bodyType = “dynamic”
end
end
end[/code]
Modified code:
[code]if “moved” == phase then
if (t.x == t.x0) or (t.u == t.y0) then
t.x = t.x
t.y = t.y
else
t.x = event.x - t.x0
t.y = event.y - t.y0
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
if ( not event.target.isPlatform ) then
event.target.bodyType = “dynamic”
end
end
end[/code]
Can anyone help me to find how to solve this small issue? You can try the behavior just downloading and running the sample app “Drag Platforms”.
Thanks in advance
[import]uid: 14235 topic_id: 7232 reply_id: 307232[/import]
[import]uid: 14235 topic_id: 7232 reply_id: 26254[/import]