Screen only showing white when using playdate.graphics.sprite.update()

I'm using playdate sdk on windows, programming in lua, and when I try to display a sprite the whole screen goes white. Anyone know what I'm doing wrong? Thank you so much for the help. Here's my code:

local gfx <const> = playdate.graphics

class("game").extends()

local function image_Init()
	Image_dice1 = gfx.image.new("images/dice-six-faces-one")
	img_d1 = gfx.sprite.new(image_dice1)
	img_d1:moveTo(0, 0)
	img_d1:add()
end

function game:init()
	image_Init()
end

function game:draw()
	gfx.sprite.update()
end

I think white may be the default background color behind all sprites. You can set it to clear if you need other stuff behind sprites, or just black to let white sprites show up.

See playdate.graphics.setBackgroundColor()

1 Like

Okay, cool! So adding that into the draw function before gfx.sprite.update() set the entire screen to black...

I check and it shouldn't be because the image is too big and filling the screen or anything. Any other ideas on what I'm misisng?

1 Like

Are you creating an instance of the "game" class? Or is that code everything?

(I see a case mismatch on "image_dice1" but I don't think it matters.)

Yeah, so this code game.lua is being run by main.lua

import "CoreLibs/graphics"
import "CoreLibs/sprites"

import "game" -- Game logic
import "screens" -- Screen logic

-- components
local game = game()
local screens = screens()

-- shortcuts
local gfx <const> = playdate.graphics

-- visual variables
local font = gfx.font.new('font/Mini Sans 2X') -- DEMO
local isFinalScoreVisible = false
local isGameVisible = false

local function loadGame()
	playdate.display.setRefreshRate(50) -- Sets framerate to 50 fps
	math.randomseed(playdate.getSecondsSinceEpoch()) -- seed for math.random
	gfx.setFont(font) 
end

local function updateGame()
	if isGameVisible then
		game:update() -- Update game

		if playdate.buttonJustPressed(playdate.kButtonA) and game:isReadyToExit() then
			screens:setFinalScore(game:getScoreString()) -- Update score screen
			isGameVisible = false
			screens:setVisible(false, true)
		end
	else
		screens:update() -- Update screens

		if playdate.buttonJustPressed(playdate.kButtonA) then
			isGameVisible = true
			screens:setVisible(false, false)
			game:setNewGame()
		end
	end
end

local function drawGame()
	gfx.clear() -- Clears the screen
	
	if isGameVisible then
		game:draw() -- Draw game
	else 
		screens:draw()
	end

	--gfx.setBackgroundColor(gfx.kColorClear)
	--playdate.timer.updateTimers()
	--gfx.sprite.update()
end

loadGame()

function playdate.update()
	updateGame()
	drawGame()
	--playdate.drawFPS(0,0) -- Debug FPS widget
end

You could try disabling the lines for setVisible and setNewGame, to test whether those functions cause isGameVisible to end up false?

I don't think that's it. I have a game I didn't include in my original post that is displaying just fine as long as I'm not doing the sprite update thing