RPG-style walking animations with AnAL

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.
Post Reply
User avatar
maage
Prole
Posts: 1
Joined: Fri Sep 28, 2012 10:45 pm
Location: Hilbert Space

RPG-style walking animations with AnAL

Post by maage »

Admittedly, I'm new to love2D (but certainly not to programming). I'm struggling to understand how I can get AnAL to read a sprite sheet and change the character direction based off the key pressed. That is, I want it to be like a Zelda or RPG style walking system where the character's sprite changes based on direction according to user input.

This is the code that I have so far:

Code: Select all

require("AnAL")

SPRITE_WIDTH = 32
SPRITE_HEIGHT = 48

function love.load()	
	img = love.graphics.newImage("sprites/chikaru.png")
	spr = newAnimation(img, SPRITE_WIDTH, SPRITE_HEIGHT, 0.2, 0)
	spr:seek(3)
end

function love.update(dt)

	if love.keyboard.isDown("left") then
		spr:seek(3)
		x = x - 100
		spr:update(dt)
	end
    if love.keyboard.isDown("right") then
		spr:seek(7)
    	x = x + 100
		spr:update(dt)
	end
    if love.keyboard.isDown("up") then
		spr:seek(11)
    	y = y - 100
		spr.update(dt)
	end
    
	if love.keyboard.isDown("down") then
		spr.seek(15)
		y = y + 100
		spr.update(dt)
    end

end

function love.draw()
	love.graphics.draw(spr, x, y)
end
What am I doing wrong? Is there a tutorial someone can point me towards? I feel pretty lost, I've just been looking at other people's source code and trying to figure out what they did.
SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm

Re: RPG-style walking animations with AnAL

Post by SudoCode »

Create a variable that is updated on input and draw the animations from that. It's no different than changing the image displayed based on keypress.
User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: RPG-style walking animations with AnAL

Post by verilog »

Hello!
This post I wrote about flipping images a while ago might be helpful for you :)

viewtopic.php?f=4&t=9825&p=60239#p60239
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: RPG-style walking animations with AnAL

Post by T-Bone »

You mix

Code: Select all

spr:update(dt)
with

Code: Select all

spr.update(dt)
They mean different things. I think the first one is the one you want, if you call spr.update(dt), the function "update" cannot know what sprite (in this case spr) you are talking about and that seems wrong.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests