"the collisionResponse property of a sprite can be set directly" How?

The documentation says:

"Instead of defining a callback, the collisionResponse property of a sprite can be set directly to one of the four collision response types. This will be faster, as the lua function will not need to be called, but does not allow for dynamic behavior."

How do we set this property?


You can just write mySprite.collisionResponse = x where x is one of

  • playdate.graphics.sprite.kCollisionTypeSlide
  • playdate.graphics.sprite.kCollisionTypeFreeze
  • playdate.graphics.sprite.kCollisionTypeOverlap or
  • playdate.graphics.sprite.kCollisionTypeBounce.

You would set the property to a function returning one of these four if the collision type for the sprite can vary at runtime. If it's constant, assigning the value directly is faster.


Thank you.

That was actually the first thing I tried.

The reason it didn't seem to work for me, is because the sprite actually doing the colliding was the other sprite.

I didn't realise that collision types only go one way. Makes sense now that I know though.

Thanks again.

1 Like