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
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito »

Mmm ... hello!

The tile tutorial should help you understand what tables & basic loops are, and how to draw quads on the screen.

Once you have understood it, probably it will be easier to get how anim8 (or AnAL, or code done by hand) works.

@Nixola: I don't know, I don't keep track of that stuff, but I'm glad you liked it!
When I write def I mean function.
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 »

Nice tutorials!!!
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 »

Wow, you miss one day on these forums, you miss everything... sorry I couldn't have helped more, but it looks like you have a solution, so that's good.
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 »

Well, I still don't know how to animate, so you didn't miss everything.
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:Well, I still don't know how to animate, so you didn't miss everything.

Here's some really terrible code of mine that will animate 4 directional player movement and 4 directional idle animations using anim8.

Code: Select all


player = {}
player.pic = love.graphics.newImage("assets/game/player.png")
player.x = 100
player.y = 100
player.speed = 100

function loadPlayer()

	lastMove = "down"

	playerAnim = newGrid(64, 64, player.pic:getWidth(), player.pic:getHeight())
	player.idledownAnim = newAnimation('loop', playerAnim('1-2,10'), 0.4)
	player.idleupAnim = newAnimation('loop', playerAnim('1-2,7'), 0.4)
	player.idlerightAnim = newAnimation('loop', playerAnim('1-2,4'), 0.4)
	player.idleleftAnim = newAnimation('loop', playerAnim('3-4, 4'), 0.4)
	player.upAnim = newAnimation('loop', playerAnim('1-4,6'), 0.2)
	player.downAnim = newAnimation('loop', playerAnim('1-4,9'), 0.2)
	player.rightAnim = newAnimation('loop', playerAnim('1-4,2'), 0.2)
	player.leftAnim = newAnimation('loop', playerAnim('1-4,3'), 0.2)
	
end

function updatePlayer(dt)

	function love.keypressed(key)
		if key == "a" then
			lastMove = "left"
		elseif key == "w" then
			lastMove = "up"
		elseif key == "d" then
			lastMove = "right"
		elseif key == "s" then
			lastMove = "down"
		end
	end
	

	player.idledownAnim:update(dt)
	player.idleleftAnim:update(dt)
	player.idleupAnim:update(dt)
	player.idlerightAnim:update(dt)
	player.upAnim:update(dt)
	player.downAnim:update(dt)
	player.rightAnim:update(dt)
	player.leftAnim:update(dt)
	
	-- Movement
	
	if love.keyboard.isDown("w") then
		player.y = math.floor(player.y - (player.speed * dt))
	end
	if love.keyboard.isDown("s") then
		player.y = math.ceil(player.y + (player.speed * dt))
	end
	if love.keyboard.isDown("a") then
		player.x = math.floor(player.x - (player.speed * dt))
	end
	if love.keyboard.isDown("d") then
		player.x = math.ceil(player.x + (player.speed * dt))
	end
	
end

function drawPlayer()

	playerIdle = love.keyboard.isDown("w", "a", "s", "d")
	
	if love.keyboard.isDown("w") then
		player.upAnim:draw(player.pic, player.x, player.y)
	elseif love.keyboard.isDown("s") then
		player.downAnim:draw(player.pic, player.x, player.y)
	elseif love.keyboard.isDown("a") then
		player.leftAnim:draw(player.pic, player.x, player.y)
	elseif love.keyboard.isDown("d") then
		player.rightAnim:draw(player.pic, player.x, player.y)
	elseif playerIdle == false then
		if lastMove == "down" then
			player.idledownAnim:draw(player.pic, player.x, player.y)
		elseif lastMove == "right" then
			player.idlerightAnim:draw(player.pic, player.x, player.y)
		elseif lastMove == "up" then
			player.idleupAnim:draw(player.pic, player.x, player.y)
		elseif lastMove == "left" then
			player.idleleftAnim:draw(player.pic, player.x, player.y)
		end
	end
	
end

What specifically are you having trouble with?
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 »

Thanks! I'm gonna check if it works!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito »

You said you already had the frames drawn. If you have them together in a image, and distributed into equal rectangles, I can tell you how to animate them via anim8, if you want.
When I write def I mean function.
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 »

Yes, please! Thank you, kikito!
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post by kikito »

Ok. Where is the image, then?
When I write def I mean function.
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 »

Here's the whole game. It's not impressive.
Attachments
helpme.love
(18.35 KiB) Downloaded 103 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest