I have been trying to rotate my game graphics and encountered some odd quirks with things not drawing.
My need for rotation is simple: I render my stage into the image of a sprite with 0,0 being the usual top,left of the screen. I want to rotate the sprite 180' so that bottom,right of the screen appears to be the origin. This should be easier than changing the co-ordinate maths throughout my game, and it will allow changing stage rotation on demand.
And I managed to reduce it to this bug report.
- dot moves down the screen based on time
- dot is drawn to sprite image
- pressing A to set rotation on sprite
- dot stops moving (sprite image stops updating)
I've tried some things, to no avail:
- forcing sprite image update
- setting dirty rect for whole screen
What is going on here?
Tested:
- 1.11.1 SDK (macOS Simulator)
- 1.13.7 SDK (macOS Simulator)
- 2.0.0-beta4 (hardware)
Controls
- A to set rotation to 180'
- B to reset rotation to 0'
Downloads
- .pdx: Rotation.pdx.zip (20.0 KB)
- lua source: Rotation.zip (1.5 KB)
import "CoreLibs/graphics"
import "CoreLibs/sprites"
local gfx <const> = playdate.graphics
SCREEN_W = playdate.display.getWidth()
SCREEN_H = playdate.display.getHeight()
gfx.setBackgroundColor(gfx.kColorBlack)
testImage = gfx.image.new( SCREEN_W,SCREEN_H, gfx.kColorClear )
gfx.pushContext(testImage)
gfx.setColor(gfx.kColorWhite)
gfx.fillCircleAtPoint(SCREEN_W//2,SCREEN_H//2,5)
gfx.popContext()
test = gfx.sprite.new( testImage )
test:moveTo(SCREEN_W//2,SCREEN_H//2)
test:add()
function playdate.AButtonDown()
test:setRotation(-180)
end
function playdate.BButtonDown()
test:setRotation(0)
end
function playdate.update()
gfx.pushContext(testImage)
testImage:clear(gfx.kColorClear)
gfx.setColor(gfx.kColorWhite)
gfx.fillCircleAtPoint(20,playdate.getCurrentTimeMilliseconds() % (SCREEN_H*10)//10,8)
gfx.popContext()
-- test:setImage(testImage)
-- playdate.graphics.sprite.addDirtyRect(0, 0, SCREEN_W,SCREEN_H)
gfx.sprite.update()
end