Page 1 of 4
Need help with animation/quads, please help!
Posted: Fri May 04, 2012 8:09 pm
by Kasperelo
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!
Re: Need help with animation/quads, please help!
Posted: Fri May 04, 2012 9:32 pm
by Puzzlem00n
Well, what do you have so far? Anything would help. Do you have the art done already, but just not coded in?
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 7:35 am
by Kasperelo
Art done, not coded. It's just how to DRAW the quads I don't understand.
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 9:57 am
by richapple
In the purpose of not breaking the spirit of programming, I will help you with pseudocode.
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
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
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 4:05 pm
by Kasperelo
Don't get it.. Srry for being a noob.
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 5:08 pm
by SudoCode
Kasperelo wrote:Don't get it.. Srry for being a noob.
Which part are you having trouble with?
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!
Posted: Sat May 05, 2012 5:23 pm
by Kasperelo
... 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!
Posted: Sat May 05, 2012 6:32 pm
by Nixola
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
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 7:05 pm
by Kasperelo
Get it. But still don't get the animation stuff. It's just drawing the quads!
Re: Need help with animation/quads, please help!
Posted: Sat May 05, 2012 7:12 pm
by SudoCode
Kasperelo wrote:Get it. But still don't get the animation stuff. It's just drawing the quads!
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.