Conflict between drawing sprites and graphics

I am trying to both render a sprite and graphics simultaneously, but when the sprites are rendered — graphics disappears.

Here is the code:

function myGameSetUp()
    gfx.drawRoundRect(10, 10, 30, 50, 5)

   -- if I comment below out, rect is shown again
    local ySprite = yLetterImage )
    ySprite:moveTo( 200, 120 )
    ySprite:setScale( 4 )

function playdate.update()

It is unclear from API reference, whether I should store graphics somewhere and then run an update on it.

Calling gfx.sprite.update() clear the screen using gfx.backgroundColor. You can either:

  • Set the background color as kColorClear with gfx.setBackgroundColor(gfx.kColorClear).
  • Move your drawing code inside a function and set this function as the background drawing callback using gfx.setBackgroundDrawingCallback()
  • Move your drawing code inside a sprite and set a low zIndex for this sprite to always be behind your other sprites.

Thank you, @Daeke!

It seems that my screen indeed was filled with background color, and I was not seeing initial render.

1 Like