It looks like you're new here. If you want to get involved, click one of these buttons!
Paddle = gideros.class(Sprite) --Input (position) = Should the paddle be on the right or the left of the screen? function Paddle:init(position) bitmap = Bitmap.new(Texture.new("textures/paddle.png")) self:addChild(bitmap) self:setSize(64, 64) --Sets the paddle position if position == "right" then self:setX(stage:getWidth() - self:getWidth() - 24) end if position == "left" then self:setX(24) end self.isFocus = false self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) self:addEventListener(Event.MOUSE_DOWN, onMouseDown, self) self:addEventListener(Event.MOUSE_MOVE, onMouseMove, self) self:addEventListener(Event.MOUSE_UP, onMouseUp, self) end function Paddle:onEnterFrame(event) local x, y = self:getPosition() if y < 0 then y = 0 end if y > application:getLogicalWidth() - self:getHeight() then y = application:getLogicalWidth()- self:getHeight() end self:setPosition(x, y) end function onMouseDown(self, event) if self:hitTestPoint(event.x, event.y) then self.isFocus = true self.y0 = event.y event:stopPropagation() end end function onMouseMove(self, event) if self.isFocus then local dy = event.y - self.y0 self:setY(self:getY() + dy) self.y0 = event.y print(self:getY()) print(application:getLogicalHeight()) event:stopPropagation() end end function onMouseUp(self, event) if self.isFocus then self.isFocus = false event:stopPropagation() end end |
Comments
In your case, each paddle should store a "touchid" instead of "isFocus" and only use the touch event whose id is equal to the paddle's touchid.
Here is an example: