I'm using animators to move bullets with collisions, and calling self:moveTo
before self:setCollideRect
prevents collision detection, which seems odd to me. It seems like a bug, but maybe there's something I don't understand? SDK Versions 2.3.1, 2.2.0, and 2.0.0 all exhibit this behavior.
function Bullet:init(x, y)
local startPoint <const> = playdate.geometry.point.new(x, 240)
local animator <const> = Animator(
DURATION,
startPoint,
playdate.geometry.point.new(x, y),
playdate.easingFunctions.outQuad
)
animator.reverses = true
Bullet.super.init(self, IMAGE)
-- Collisions do not work when calling moveTo before setCollideRect
self:moveTo(startPoint.x, startPoint.y)
self:setCollideRect(self.x, self.y, self.width, self.height)
-- Collisions work when calling moveTo after setCollideRect rather than
-- before calling setCollideRect
self:moveTo(startPoint.x, startPoint.y)
self:setGroups({BULLET_GROUP})
self:setCollidesWithGroups({TARGET_GROUP})
self:setAnimator(animator, true)
self:add()
end
No collisions when calling self:moveTo
before self:setCollideRect
.
Collisions when calling self:moveTo
after self:setCollideRect
.