Sprite grouping

Sprites are a very powerful tool for managing graphics in the Playdate. But they do not have a very important feature - grouping.
Yes, making an offset on the x-axis or y-axis of a set of sprites is easy, but making a change in the angle or scale is a big problem. Does anyone have any thoughts on how to resolve this issue?

2 Likes

For cases where the individual sprites don’t move a lot relative to each other I draw them to another sprite first and then move that around and only redraw when necessary, but I agree it would be nice to have some kind of container for more dynamic cases.

since there are no ready-made solutions, I decided to write it :blush:
coming soon

2 Likes

Sprite container (WIP)
Each rectangle is a sprite. The small black rectangle inside is the center point of the sprite. The small circle is the center point of the sprite group.

Rotation of the group around the control point, some sprites have their own rotation animation.
group-1
group-2

Rotation of the group plus movement.
group-3
group-4
group-5

Zoom. Still with the scale position bug. :laughing:
group-6

Without scale, everything is great (will be)! :blush:
group-7

to be continued!

3 Likes

Sprite Container Beta is here!
Sprite Container - 1.zip (31.7 KB)

Demo: 3 different sprites in a container
Moving
SpriteContainer-move-1
Rotation
SpriteContainer-rotation-1
Moving the center point
SpriteContainer-center-point-1

Getting started

import 'Lib/SpriteContainer'
local container = SpriteContainer(200, 120, sprite1, sprite2)

Supported:

container:moveTo(x, y)
container:moveBy(x, y)
container:getPosition()
container:getCenterPoint()
container:setRotation(angle)
container:getRotation()
container:getBounds()
container:getBoundsRect()
container:getSize()
container:setZIndex(index)
container:getZIndex()

Extra:

container:addSprite(...)
container:removeSprite(...)
container:checkSprite(sprite)
container:setCenterPoint(x, y)
container:getCenterPointPosition()

Not supported:
A scaling bug in the API does not allow you to implement these features. I hope this bug will be corrected.

container:setSize(width, height)
container:setCenter(x, y)
container:getCenter()
container:setScale(xScale, [yScale])
container:getScale()
8 Likes