[HELP] Drawable disappears the first frame
Posted: 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!
main.lua
player.lua
manager.lua
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"
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
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
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