Hi! I need some help for my animations, 'cause I'm pretty n00b at programming. Please
keep it simple! I don't know how to draw the animations!
Thanks!
Need help with animation/quads, please help!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Need help with animation/quads, please help!
Well, what do you have so far? Anything would help. Do you have the art done already, but just not coded in?
I LÖVE, therefore I am.
Re: Need help with animation/quads, please help!
Art done, not coded. It's just how to DRAW the quads I don't understand.
Re: Need help with animation/quads, please help!
In the purpose of not breaking the spirit of programming, I will help you with pseudocode.
Combined from my own previous experiences and from this demo
Keep in mind that you can use other libraries like anim8 (forum thread demo) or AnAL
Code: Select all
function love.load()
make a table (later will be stated as frames_table) = {
up = { that has
love.graphics.newQuad(... , ... , ),
love.graphics.newQuad(... , ... , ),
...
},
down = { quads for
love.graphics.newQuad(... , ... , ),
love.graphics.newQuad(... , ... , ),
...
},
left = { every frame
love.graphics.newQuad(... , ... , ),
love.graphics.newQuad(... , ... , ),
...
},
right = { with love.graphics.newQuad(... , ... , )
love.graphics.newQuad(... , ... , ),
love.graphics.newQuad(... , ... , ),
...
}
}
animationTimer = 0
player = {
x = 10,
y = 10,
direction = ""
} -- Just a random player table to hold values
end
and for love.update(dt)
if we're moving then
animationTimer = (animationTimer + 10 * dt) % #frames_table
-- 10 is your animation speed
-- % means that animation timer will reset itself and loop
end
-- There you can change player direction
if key == "up" then
player.y = player.y - 10 * dt and so on
elseif key == "down" then
elseif key == "left" then
elseif key == "right" then
end
end
easiest part love.draw()
love.graphics.drawq(sprite_sheet_image, frames_table[player.direction][math.ceil(iterator)], player.x, player.y)
end
-- This is the ugliest part because I didn't think of a better approach
love.keypressed(key)
if key == "up" or key == "down" or key == "left" or key == "right" then
player.direction = key
we're moving = true
end
end
love.keyreleased(key)
if (key == "up" or key == "down" or key == "left" or key == "right") and player.direction == key then
--player.direction = key
we're moving = false
end
end
Keep in mind that you can use other libraries like anim8 (forum thread demo) or AnAL
Re: Need help with animation/quads, please help!
Don't get it.. Srry for being a noob.
Re: Need help with animation/quads, please help!
Which part are you having trouble with?Kasperelo wrote:Don't get it.. Srry for being a noob.
In love.load, he's making a new table with directions, each with their own animations (quads). In love.update, he's then setting the animation to update every 10 when moving in a specific direction. You then draw the specific quad based on animation timer and the direction you're moving in.
Re: Need help with animation/quads, please help!
... You just said the stuff I don't understand. I don't get what's up with all the [] and stuff. I mostly inderstand tables, tho'
Re: Need help with animation/quads, please help!
Your last sentences can't be true at the same time... Anyway:
Code: Select all
a_table = {'Something', 'Something else'} --Here I created a table with the string 'Something' at the index/position 1 and 'Something else' at the index/position 2
a_table.index = 'Another thing' --Here I put the string 'Another thing' at the index 'index', in the table 'a_table'
print(a_table[1]) --This will print the string 'something', because "a_table[1]" is like saying "Use the data at the index 1 in the table a_table"
print(a_table.index) --This will print 'Another thing', because "a_table.index" is like saying "Use the data at the index "index" (it's a string, not a variable, if you use the dot notation) in the table a_table"
print(a_table['index']) --this is like the above
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Need help with animation/quads, please help!
Get it. But still don't get the animation stuff. It's just drawing the quads!
Re: Need help with animation/quads, please help!
Set a variable with the image you want displayed for the player, which would be a quad in this instance. Every X (let's say 10 pixels moved in a direction), update the variable with the next quad.Kasperelo wrote:Get it. But still don't get the animation stuff. It's just drawing the quads!
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests