Page 1 of 1

[HELP] Drawable disappears the first frame

Posted: Sat Apr 13, 2019 8:24 am
by nice
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! :awesome:

main.lua

Code: Select all

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

function love.load()
  
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
  -- Player Radians (or Rotation)
  Player.Radians = 0
  -- 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.Radians,
                     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

Re: [HELP] Drawable disappears the first frame

Posted: Sat Apr 13, 2019 1:26 pm
by keharriso
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! :awesome:
For some reason the square doesn't disappear on my Windows 10 setup. Also works on my Debian setup.

Re: [HELP] Drawable disappears the first frame

Posted: Sat Apr 13, 2019 2:11 pm
by zorg
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.

Re: [HELP] Drawable disappears the first frame

Posted: Mon Apr 15, 2019 6:49 am
by nice
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.
Thank you for the reply!
I'll check the version when I get home but I do know that I use (1,1,1,1) to set the colors.