[HELP] Drawable disappears the first frame

General discussion about LÖVE, Lua, game development, puns, and unicorns.
nice
Party member
Posts: 181
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

[HELP] Drawable disappears the first frame

Hello everyone!

I'm gonna get straight into it, in this project I'm currently working on my drawable image in "player.lua" disappears as soon as the program starts. I'm a bit at a loss about what I should do.
Usually, my solution is to set the color to white after I've drawn something but for some reason, it doesn't work.

What am I missing? Because at the moment I can't really see what's wrong..
Below you can find the code and have a nice weekend!

main.lua

Code: Select all

Player = require "player"
Manager = require "manager"

end

function love.update(dt)
Player:update(dt)
Manager:update(dt)
end

function love.draw()
Player:draw()
Manager:draw()
end

function love.keypressed(key)
end

function love.keyreleased(key)
end

player.lua

Code: Select all

  --Manager = require "manager"

-- Player Table
Player = {}
-- Player Graphics
Player.Sprite = love.graphics.newImage("Graphics/Square.png")
-- Player position on X/Y
Player.posX = love.graphics.getWidth() * 0.5
Player.posY = love.graphics.getHeight() * 0.5
-- Increases the size on X/Y
Player.scaleFactorX = 1
Player.scaleFactorY = 1
-- Changes where the origin is on the Player
Player.originOffsetX = 0
Player.originOffset = 0
-- Player's Width/Height
Player.Width = 32
Player.Height = 32
-- Player Speed/Velocity
Player.Speed = 100
Player.velocityX = 0
Player.velocityY = 0
--Player Direction
Player.Direction = 1
Player.currentDirection = Player.Direction

function Player:update(dt)

-- Moves the Player Left/Right
if love.keyboard.isDown('left', 'a') then
self.posX = self.posX - self.Speed * dt
elseif love.keyboard.isDown('right','d') then
self.posX = self.posX + self.Speed * dt

-- Moves The Player Up/Down
elseif love.keyboard.isDown('up','w') then
self.posY = self.posY - self.Speed * dt
elseif love.keyboard.isDown('down', 's') then
self.posY = self.posY + self.Speed * dt
end
end

function Player:draw()
-- Draws the Player Sprite
--love.graphics.setColor(1,1,1,1)
love.graphics.draw(self.Sprite,
self.posX,
self.posY,
self.scaleFactorX,
self.scaleFactorY,
self.originOffsetX,
self.originOffsetY)

love.graphics.setColor(1,1,1,1)

end

return Player

manager.lua

Code: Select all

Player = require "player"

Manager = {}
--rgb(46, 49, 49)
-- love.graphics.setColor(red, green, blue, alpha)
Manager.standardColor = {1, 1, 1, 1}
Manager.backgroundColor = {1 * 102, 1 * 51, 1 * 153, 1}
--rgba(102, 51, 153, 1)
function Manager:update(dt)
end

function Manager:draw()
love.graphics.setColor(self.backgroundColor)
love.graphics.setColor(self.standardColor)
end

return Manager

Have a good day!

keharriso
Citizen
Posts: 71
Joined: Fri Nov 16, 2012 9:34 pm

Re: [HELP] Drawable disappears the first frame

nice wrote:
Sat Apr 13, 2019 8:24 am
Hello everyone!

I'm gonna get straight into it, in this project I'm currently working on my drawable image in "player.lua" disappears as soon as the program starts. I'm a bit at a loss about what I should do.
Usually, my solution is to set the color to white after I've drawn something but for some reason, it doesn't work.

What am I missing? Because at the moment I can't really see what's wrong..
Below you can find the code and have a nice weekend!
For some reason the square doesn't disappear on my Windows 10 setup. Also works on my Debian setup.
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games

zorg
Party member
Posts: 2550
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [HELP] Drawable disappears the first frame

Usually, you want to set color before you draw something, not the other way around, it's more straightforward.

And depending on what löve version you use, colors are in the [0,1] interval with the current versions, so {1 * 102, 1 * 51, 1 * 153, 1} is definitely wrong, unless you use something like 0.10 or earlier... but since the order of your calls goes like:
1. draw image
2. setcolor white
3. setcolor brighter than max brightness
4. setcolor white
it shouldn't even matter... ultimately we'd need a whole project to test.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

nice
Party member
Posts: 181
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [HELP] Drawable disappears the first frame

zorg wrote:
Sat Apr 13, 2019 2:11 pm
Usually, you want to set color before you draw something, not the other way around, it's more straightforward.

And depending on what löve version you use, colors are in the [0,1] interval with the current versions, so {1 * 102, 1 * 51, 1 * 153, 1} is definitely wrong, unless you use something like 0.10 or earlier... but since the order of your calls goes like:
1. draw image
2. setcolor white
3. setcolor brighter than max brightness
4. setcolor white
it shouldn't even matter... ultimately we'd need a whole project to test.