I need help :(
Posted: Sat Jul 04, 2020 11:04 am
Hi,
I am trying to make a platform game using LÖVE and LUA.
I have a spritesheet of my character, I have made a lot of things in order to obtain the Quads, but I do not know why it does not render properly.
I think it is because the pixel each character sprite is, do you know how I may do it?
Thank you
I let part of my player code:
player = {}
require 'Animation'
--this is where we set atributes of the player
function player:load()
self.x = 0
self.y = 0
self.width = 40
self.height = 54
-- offset from top left to center to support sprite flipping
self.xOffset = 6
self.yOffset = 10
self.texture = love.graphics.newImage('Graphics/character.png')
-- animation frames
self.frames = {}
-- current animation frame
self.currentFrame = nil
-- used to determine behavior and animations
self.state = 'idle'
-- determines sprite flipping
self.direction = 'left'
-- x and y velocity
self.xvel = 0
self.yvel = 0
-- initialize all player animations
self.animations = {
['idle'] = Animation({
texture = self.texture,
frames = {
love.graphics.newQuad(2, 2, self.width, self.height, self.texture:getDimensions())
}
}),
}
self.animation = self.animations['idle']
self.currentFrame = self.animation:getCurrentFrame()
self.behaviours = {
['idle'] = function(dt)
if love.keyboard.isDown('left') then
self.direction = 'left'
self.xvel = - self.speed
self.state = 'walking'
elseif love.keyboard.isDown('right') then
self.direction = 'right'
self.velx = self.speed
self.state = 'walking'
else
self.xvel = 0
end
end
}
end
function player:update()
if gameState == 'play' then
self.behaviors[self.state](dt)
self.animation:update(dt)
self.currentFrame = self.animation:getCurrentFrame()
self.x = self.x + self.xvel * dt
end
end
--this is where the player is drawn from
function player:render()
local scaleX
-- set negative x scale factor if facing left, which will flip the sprite
-- when applied
if self.direction == 'right' then
scaleX = 1
else
scaleX = -1
end
-- draw sprite with scale factor and offsets
love.graphics.draw(self.texture, self.currentFrame, math.floor(self.x + self.xOffset),
math.floor(self.y + self.yOffset), 0, scaleX, 1, self.xOffset, self.yOffset)
end
I am trying to make a platform game using LÖVE and LUA.
I have a spritesheet of my character, I have made a lot of things in order to obtain the Quads, but I do not know why it does not render properly.
I think it is because the pixel each character sprite is, do you know how I may do it?
Thank you
I let part of my player code:
player = {}
require 'Animation'
--this is where we set atributes of the player
function player:load()
self.x = 0
self.y = 0
self.width = 40
self.height = 54
-- offset from top left to center to support sprite flipping
self.xOffset = 6
self.yOffset = 10
self.texture = love.graphics.newImage('Graphics/character.png')
-- animation frames
self.frames = {}
-- current animation frame
self.currentFrame = nil
-- used to determine behavior and animations
self.state = 'idle'
-- determines sprite flipping
self.direction = 'left'
-- x and y velocity
self.xvel = 0
self.yvel = 0
-- initialize all player animations
self.animations = {
['idle'] = Animation({
texture = self.texture,
frames = {
love.graphics.newQuad(2, 2, self.width, self.height, self.texture:getDimensions())
}
}),
}
self.animation = self.animations['idle']
self.currentFrame = self.animation:getCurrentFrame()
self.behaviours = {
['idle'] = function(dt)
if love.keyboard.isDown('left') then
self.direction = 'left'
self.xvel = - self.speed
self.state = 'walking'
elseif love.keyboard.isDown('right') then
self.direction = 'right'
self.velx = self.speed
self.state = 'walking'
else
self.xvel = 0
end
end
}
end
function player:update()
if gameState == 'play' then
self.behaviors[self.state](dt)
self.animation:update(dt)
self.currentFrame = self.animation:getCurrentFrame()
self.x = self.x + self.xvel * dt
end
end
--this is where the player is drawn from
function player:render()
local scaleX
-- set negative x scale factor if facing left, which will flip the sprite
-- when applied
if self.direction == 'right' then
scaleX = 1
else
scaleX = -1
end
-- draw sprite with scale factor and offsets
love.graphics.draw(self.texture, self.currentFrame, math.floor(self.x + self.xOffset),
math.floor(self.y + self.yOffset), 0, scaleX, 1, self.xOffset, self.yOffset)
end