Need help with animation/quads, please 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.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Need help with animation/quads, please help!

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

Re: Need help with animation/quads, please help!

Post by Puzzlem00n »

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

Re: Need help with animation/quads, please help!

Post by Kasperelo »

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

Re: Need help with animation/quads, please help!

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

Re: Need help with animation/quads, please help!

Post by Kasperelo »

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

Re: Need help with animation/quads, please help!

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

Re: Need help with animation/quads, please help!

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

Re: Need help with animation/quads, please help!

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: Need help with animation/quads, please help!

Post by Kasperelo »

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

Re: Need help with animation/quads, please help!

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot], slime and 7 guests