I've got a game in development called "Fling". Here's a screenshot.
Basically, I'm trying to get a ball shot up in between that gap. However, since these sprites are squares instead of circles, I'm trying to utilize alphaCollision to detect if the circles are overlapping or not.
Specifically, I'm trying to figure out how to utilize alphaCollision in tandem with moveWithCollisions. Here is a snippet of code demonstrating what I'm trying to do:
function FlyingBall:update()
self.xCoord = self.xCoord + self.xVelocity
self.yCoord = self.yCoord + self.yVelocity
local actualX, actualY, collisions, _ = self:moveWithCollisions(self.xCoord, self.yCoord)
for i = 1, #collisions do
local collision = collisions[i]
if(collision.sprite:alphaCollision(collision.other)) then
print("You are _actually_ colliding right now")
local newBallXIndex, newBallYIndex = calculateIndices(actualX, actualY, 'ball')
self:remove()
Ball(newBallXIndex, newBallYIndex, ballSelector.patternName)
end
end
end
I never get inside the collision.sprite:alphaCollision(collision.other) conditional.
I think I'm doing something fundamentally wrong, but the docs don't provide any code examples that might help guide me to use this function.
I haven’t worked extensively with moveWithCollisions, but my guess is that you have a non-overlap collision response on one or both of the sprites which isn’t allowing them to get close enough together for the alpha collision to be true.
This was the approach I’ve been thinking about in my head since writing this post. I’ll give this a shot. I’d still love to hear from panic or - would love to have the docs updated with a proper example of using this method.
I thought the same thing, but I slowed everything down and shot a FlyingBall through two rows of Balls - the entire time (alphaOverlap certain, right) I had debug statement saying “no collision”. When it hit the top wall it collided successfully with moveWithCollision.
I tried your code and it works fine. It just needs FlyingBall:setCollideRect(0, 0, width, height)
and FlyingBall.collisionResponse = playdate.graphics.sprite.kCollisionTypeOverlap