Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Love2D beginner- why are Shape colors being applied images?

A topic by hyperking created Feb 03, 2017 Views: 1,135 Replies: 3
Viewing posts 1 to 3
(1 edit)

Hello, I have an issue where my game is applying the last shape color to my jpg image.

My game loads a background image and then loads a table of shape objects. Each shape object has a different color which appears correctly. However, when the game opens the last shape color is applied to the image.



Here is my main lua code

function love.load()
-- load game
love.graphics.setColor(255, 255, 255, 255)
love.graphics.setBackgroundColor(255, 255, 255, 255)
vader = love.graphics.newImage(Levels.loadBg(1,"vader.jpg"))
-- load players
loadPlayers = Player:loadPlayers(Levels[1].shapes)
end
function love.draw ()
love.graphics.draw(vader,world.centerX /2,0,0,0.4,0.4 )
Player:drawAll()
end

The Player:drawAll() method is looping all shapes and drawing them to the page using these lines.

love.graphics.setColor(fillcolor)
love.graphics.rectangle(mode, x, y,width, height)
Admin(+1)

You'll need to reset the color to white immediately above the call to draw vader. It's keeping the color from the end of the previous frame when drawing the image on the next.

(+1)

Thanks @leafo. I realized this after looking at other examples.

A bit counter intuitive for this behavior to take place. I've set a default color at the end of my draw function so it works now.

In general, everything that you draw should be responsible for setting its own global state - shaders, colors, filter modes, etc.

Admin moved this topic to General Development