Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Responsive touch event when world is scrolling — Gideros Forum

Responsive touch event when world is scrolling

AzurlakeAzurlake Member
edited July 2014 in General questions
Hello guys,

I've got a "kind of" runner game, with spawning objects the player's got to tap to get rid of them. The problem is, the world scrolls faster and faster as the player goes further in the endless ground, and at some point (not very far, really; anybody could reach that far the very first time) the tap event doesn't work as expected. It seems the tap event is being captured some dozen pixels away from where I test the condition, and sometimes even I've made sure I tap on the rigth place, the event is not even firing. How would you handle this scenario? What type of event/combination of events?

Here's the code I'm using for the object I'm tapping:

--[[--------------------------------------------------------------------------
- TAPME CLASS (****this is a sprite to tap****)
--------------------------------------------------------------------------]]--

TapMe = gideros.class(Sprite)

local TILE_HEIGHT = 143;

function TapMe:init()

self.frames = {};

for i = 1, 4 do
self.frames[i] = Bitmap.new(TextureRegion.new(Texture.new("images/tapme" .. i .. ".png", true)))
end

self.nframes = #self.frames
self.frame = 1
self:addChild(self.frames[1])
self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self)
self:addEventListener(Event.MOUSE_DOWN, self.dismissObject, self)
self:addEventListener(Event.TOUCHES_BEGIN, self.dismissObject, self)

end


function TapMe:setPos(x, y, tilemapW, tilemapH)
for i = 1, #self.frames do
self.frames[i]:setPosition(TILE_HEIGHT * (x - 1) + (tilemapW - 1) + self:getWidth() / 4 - 42, TILE_HEIGHT * (y - 1 + (tilemapH - 1)) - 5)
end

end


function TapMe:dismissObject(event)
local touched = false;
if (event:getType() == Event.MOUSE_DOWN) then
if (self:hitTestPoint(event.x, event.y)) then
touched = true;
event:stopPropagation();
end
elseif (event:getType() == Event.TOUCHES_BEGIN) then
if (self:hitTestPoint(event.touch.x, event.touch.y)) then
touched = true;
event:stopPropagation();
end
end
if (touched) then
self:removeEventListener(Event.MOUSE_DOWN, self.dismissObject, self);
self:removeEventListener(Event.TOUCHES_BEGIN, self.dismissObject, self);
self:removeEventListener(Event.ENTER_FRAME, self.onEnterFrame, self);
print("Tapped on " .. self.firename);
self:removeFromParent();
end
end


function TapMe:onEnterFrame()
self:removeChild(self.frames[math.floor(self.frame)])
self.frame = self.frame + 0.1
if self.frame >= self.nframes + 1 then
self.frame = 1
end
self:addChild(self.frames[math.floor(self.frame)])
end


--[[--------------------------------------------------------------------------
- END
--------------------------------------------------------------------------]]--

The OnEnterFrame is updating the world in the Level class, with b2World:step(1/60, 6, 3).
Can anybody help a bit?

Also, the game starts running slow after 1 minute or so; I'm not sure if this way I handle the tap events and objects being tapped is leaking any resources... surely, it does. But where?

Thanks.

Likes: Azurlake

+1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.