Best way to animate?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Best way to animate?

Post by retrotails »

I want to make a game that's very basic and should run fast on old hardware, and animation seems to be one of those things you can do many different ways. Which way is best?
  • Making a sprite sheet and making a new quad every frame
  • Making a sprite sheet and a quad for every frame then flip through the quads
  • Making individual images and using love.graphics.draw() instead of love.graphics.drawq()
  • Other
I'd like to make the animation engine myself so it has everything I need and nothing extra, and I don't want much RAM or disk use if I decide to use the Android port of Love later on.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Best way to animate?

Post by Roland_Yonaba »

I think that quads are the best solution, when you want to draw an animation.
IMHO.
You can make some tests, by yourself.
Try using each of the ways you've listed, make some *.love files, run them and profile how behaves the memory usage, running speed, etc.
And concerning animations, tons of premade tools exists.
Some have even kinky names.
See anim8, anAL :3
Though, If you don' twant to use premade tools, see how thse libs work. They use quads.
PamelaFEvans
Prole
Posts: 1
Joined: Sat Aug 04, 2012 7:00 am
Location: Binghamton, NY 13901, US
Contact:

Re: Best way to animate?

Post by PamelaFEvans »

local anim8 = require 'anim8'

local image, animation

function love.load()
image = love.graphics.newImage('path/to/image.png')
local g = anim8.newGrid(32, 32, image:getWidth(), image:getHeight())
animation = anim8.newAnimation('loop', g('1-8,1'), 0.1)
end

function love.update(dt)
animation:update(dt)
end

function love.draw()
animation:draw(image, 100, 200)
end
Try this way...Thanks,
Elena
Create easy photo to canvas online.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Best way to animate?

Post by retrotails »

Though less versatile, it fits my needs. The animation is a strip. All frames in the strip must be the same size and square. The width and height of each frame is determined by the height of the strip. The number of frames is automatic. This is what I used to test it. Left & right change animations. You can throw anything into the /tex folder that fits these specifications to see it animated.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Best way to animate?

Post by retrotails »

Kinda should be in support/development but I didn't want to make a new thread.
The function loaddie(), which I don't know what to name, has to be called for every...single...animation. How can I loop through tables with names and not numbers?
For the demo, use left & right click to place 2 different animations and middle click to remove the most recent one. Their animations are independent. Lots of things like the number & size of frames can be automatically detected or manually set.
Also, should I use garbage collection? I don't know how data is stored or how useful it'd be.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Best way to animate?

Post by retrotails »

Triple post... this happens often on my many empty threads. anim.lua is sort of a library, but I don't know how easy it is to understand. Anyway, things are mostly autogenerated now (pretty much everything that can be) and you can use the arrow keys to select an animation. All animations are absolutely 100% independent, with different framerates and independent frame positions.
This is the last update.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Best way to animate?

Post by kikito »

retrotails wrote: anim.lua is sort of a library, but I don't know how easy it is to understand
I can assure you, it is a library :3 . Is there any particular place where you have difficulties?
When I write def I mean function.
Devon Peak
Prole
Posts: 7
Joined: Sat May 19, 2012 5:42 pm
Location: Streetsboro, OH
Contact:

Re: Best way to animate?

Post by Devon Peak »

I'm trying to use anim8 because its easier than AnAL, but I get an error that says

lib_animation.lua:36 There is no frame for x = 10, y = 1
(I renamed anim8.lua to lib_animation)
(The error isn't at lib_animation:36. It's at player.lua:10

Code: Select all

g("10-10,1")
)
(The sprite sheet I'm using is attached)

main.lua

Code: Select all

require "lib_camera"
require "player"

function love.load()
	screen_width = love.graphics.getWidth()
	screen_height = love.graphics.getHeight()
	
	camera_width = 2000
	camera_height = 0
	
	camera:setBounds(0,0,camera_width,camera_height)
end

function love.update(dt)
	camera:setPosition(player.x - 25,player.y)
	
	anim_playerStandL:update(dt)
	anim_playerStandR:update(dt)

	anim_playerL:update(dt)
	anim_playerR:update(dt)
	
	player_gravity(dt)
	player_movement(dt)
end

function love.draw()
	camera:set()
	draw_player()
	camera:unset()
end

-- camera
function math.clamp(x, min, max)
  return x < min and min or (x > max and max or x)
end
player.lua

Code: Select all

local anim8 = require "lib_animation"

--load sprites
spr_player = love.graphics.newImage("sprites/player/spr_player.png")

--create grids
local g = anim8.newGrid(32,32,spr_player:getWidth(),spr_player:getHeight())

-- create animations
anim_playerStandL = anim8.newAnimation("loop", g("10-10,1"),0.3)
anim_playerStandR = anim8.newAnimation("loop", g("9-9,1"),0.3)

anim_playerL = anim8.newAnimation("loop", g("5-8,1"),0.3)
anim_playerR = anim8.newAnimation("loop", g("1-4,1"),0.3)

obj_player = anim_playerStandR

player = {
x = 50,
y = 10,
xvel = 0,
yvel = 0,
jump = 10,
speed = 5,
friction = 5.5,
}

gravity = 500

function player_gravity(dt)
	player.yvel = player.yvel + gravity * dt
	player.y = player.y + player.yvel * dt
	
	if player.y > screen_height - obj_player:getHeight() then
		player.yvel = 50
		player.y = screen_height - obj_player:getHeight()
	end	
end

function draw_player()
	love.graphics.draw(obj_player,player.x,player.y)
end

function player_movement(dt)
	player.x = player.x + player.xvel
	player.xvel = player.xvel * (1 - math.min(dt * player.friction,1))
	
	if love.keyboard.isDown("left") and
	player.xvel > -5 then
		player.xvel = player.xvel - (player.speed * dt)
			obj_player = anim_playerL
		
	elseif love.keyboard.isDown("right") and
	player.xvel < 5 then
		player.xvel = player.xvel + (player.speed * dt)
			obj_player = anim_playerR
	end	
end

function love.keyreleased(key)
	-- quit game
	if key == "escape" then
		love.event.push("quit")
	end
end	
Attachments
spr_player.png
spr_player.png (1.02 KiB) Viewed 5694 times
Aspiring fine artist, graphic designer, and game developer.
website: http://www.devonpeak.wordpress.com
twitter: http://www.twitter.com/_devonpeak
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Best way to animate?

Post by Zeliarden »

Code: Select all

g("10-10,1")
makes a grid from row(x) 10 to 10 on column(y) 1
spr_player.png has 4 rows and 3 columns
try somesing like

Code: Select all

g("1-4,1")
that make an animation grid of the first row in you picture (of four similar arrows?)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Best way to animate?

Post by kikito »

Like Zeliarden is saying, the problem is that "10-10,1" literally means "get all the quads that result from iterating over x, starting in 10 and ending in 10, and using y=1". This only gives one frame: x=10,y=1. Your image does't have that frame (it only goes until x=4), hence the error.
When I write def I mean function.
Post Reply

Who is online

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