-
Notifications
You must be signed in to change notification settings - Fork 0
Entity
UnbelievableFlavour edited this page Aug 22, 2022
·
6 revisions
An entity in Cotton is an interactable sprite that you can write custom code for.
Usually you would want to setup some stuff when initialising the Entity. Here is an example of a basic Floppy, initialised with a collision type "overlap", and an image.
class("Floppy", {}).extends(EntityTemplate)
function Floppy:init(ldtk_entity)
-- Calls the default initialization functions.
Floppy.super.init(self, ldtk_entity)
-- Set the collision to overlap.
self:setCollisionType(collisionTypes.overlap)
-- Set the image to a floppy.
self:setImage("images/floppy")
end
Cotton supports all Playdate SDK collision types. By default an entity will collide with the player by freeze
.
Collision type can be set like so:
self:setCollisionType(collisionTypes.overlap)
Possible options:
collisionTypes.freeze
collisionTypes.slide
collisionTypes.overlap
collisionTypes.bounce
The image can be set like so:
self:setImage("images/floppy")
An animated image can be set like so:
self:setImage("images/floppy", { animated = true, delay = 500, loop = true })
An entity can be removed like so:
self:remove()