Cannot invert Circle PLS help (Lua)

Hi I am new to quite new to programming and wanted to make a little metroidvainia with the Tutorial from squidGod(https://www.youtube.com/watch?v=7GbUxjE9rRM&t=3124s) as an foundation.

But.. when I tried to add shooting mechanics I wasn`t able to invert the
circular bullets, so they could show up on the Black screen.

Could anyone please tell me what I did wrong and give me an solution?

Thanks in advance. :slight_smile:

Here is the code:

local pd <const> = playdate
local gfx <const> = pd.graphics

class('Bullet').extends(gfx.sprite)

function Bullet:init(x, y, speed)
    local original_draw_mode = gfx.getImageDrawMode()
    gfx.setImageDrawMode( playdate.graphics.kDrawModeNXOR )
    local bulletSize = 4
    local bulletImage = gfx.image.new(bulletSize * 2, bulletSize * 2)
    gfx.pushContext(bulletImage)
        gfx.fillCircleAtPoint(bulletSize, bulletSize, bulletSize)
        --gfx.drawCircleAtPoint(bulletSize, bulletSize, bulletSize)
    gfx.popContext()
    self:setImage(bulletImage)

    self:setZIndex(Z_INDEXES.Projectile)
    self:setTag(TAGS.Projectile)
    self:setCollideRect(0, 0, self:getSize())
    self.speed = speed
    self:moveTo(x, y)
    self:add()
    gfx.setImageDrawMode( original_draw_mode )
end

function Bullet:update()
    self.removeOnCollision = true
    self:moveWithCollisions(self.x + self.speed, self.y)
end

PushContext resets the context (all graphics settings) so the previous drawimagemode is forgotten. PopContext restores the context.

So you would move the drawimagemode options inside the context. But I'm not sure that will have the effect you're after because that doesn't affect fillcircle.

What you're probably looking for is setting the draw colour inside the context.

2 Likes

Yeah… the invert function really didn‘t work
with the fillcircle/drawcircle function.:sweat_smile:
I had to change it to gfx.setcolor(gfx.kWhite) and put it in popcontext to run as intended.

Thx for your advice.:+1:

2 Likes