I need help :(

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Jorgealfue_10
Prole
Posts: 1
Joined: Sat Jul 04, 2020 10:54 am

I need help :(

Post by Jorgealfue_10 »

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 :awesome:

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
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: I need help :(

Post by pgimeno »

Well, where do you want the quads to be? Does the idle quad really start 2 pixels right and 2 pixels down the border as your code says? Does it have only 1 frame? Note that you need to call newQuad once per frame of the animation, telling it the position of the image within the texture.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: I need help :(

Post by zorg »

Also please use [ code ] tags so your posted code is more readable.
Me and my stuff :3True 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 210 guests