Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

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!
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

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.
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Art done, not coded. It's just how to DRAW the quads I don't understand.
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

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
...
},
...
},
left = { every frame
...
},
right = { with 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
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Don't get it.. Srry for being a noob.
SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm

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.
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

... 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'
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

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
li = love.image
lg = love.graphics
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Get it. But still don't get the animation stuff. It's just drawing the quads!
SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm