About drawFaded

have some code like this , all work :

local fade_img = gfx.image.new(200, 200, gfx.kColorBlack)
fade_img:drawFaded(0, 0, 0.1, gfx.image.kDitherTypeBayer8x8)
local fade_sprite = gfx.sprite.new(fade_img)
fade_sprite:add()
fade_sprite:moveTo(100,100)


but while i call
gfx.sprite.update()
in playdate.update() loop , i got a all black square , why is that happen ? all i need is keep the "fade sprite" unchanged .

Is the background behind the Sprite white? It would need to be. The faded image will be partially transparent.

yes , the backgorund is white , without the line : gfx.sprite.update() call in the playdate.update() , i can see the partially transparent square . but if i put this line in , the suare is completely black . but dont know why .

OK, so this:

fade_img:drawFaded(0, 0, 0.1, gfx.image.kDitherTypeBayer8x8)

draws the image to the screen.

so when you activate sprite updates it is drawing the correct all black sprite image.

What you want to do is:

local fade_sprite = gfx.sprite.new(fade_img:fadedImage(0.1, gfx.image.kDitherTypeBayer8x8))

which will assign the faded image to the sprite.

then it will work with playdate.graphics.sprite.update()

thank you matt , it works like a charm .
and i review the SDK document .

playdate.graphics.image:drawFaded(x, y, alpha, ditherType)
Draws a partially transparent image with its upper-left corner at location (x, y)

playdate.graphics.image:fadedImage(alpha, ditherType)
Returns a faded version of the caller.

I still didn't look carefully; the two are completely different. thank you for your help !

1 Like