- 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
Best way to animate?
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Best way to animate?
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?
- 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?
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
Though, If you don' twant to use premade tools, see how thse libs work. They use quads.
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
Though, If you don' twant to use premade tools, see how thse libs work. They use quads.
-
- Prole
- Posts: 1
- Joined: Sat Aug 04, 2012 7:00 am
- Location: Binghamton, NY 13901, US
- Contact:
Re: Best way to animate?
Try this way...Thanks,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
Elena
Create easy photo to canvas online.
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Best way to animate?
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.
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Best way to animate?
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.
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.
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Best way to animate?
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.
This is the last update.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Best way to animate?
I can assure you, it is a library . Is there any particular place where you have difficulties?retrotails wrote: anim.lua is sort of a library, but I don't know how easy it is to understand
When I write def I mean function.
-
- Prole
- Posts: 7
- Joined: Sat May 19, 2012 5:42 pm
- Location: Streetsboro, OH
- Contact:
Re: Best way to animate?
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)
(The sprite sheet I'm using is attached)
main.lua
player.lua
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
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
Aspiring fine artist, graphic designer, and game developer.
website: http://www.devonpeak.wordpress.com
twitter: http://www.twitter.com/_devonpeak
website: http://www.devonpeak.wordpress.com
twitter: http://www.twitter.com/_devonpeak
Re: Best way to animate?
Code: Select all
g("10-10,1")
spr_player.png has 4 rows and 3 columns
try somesing like
Code: Select all
g("1-4,1")
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Best way to animate?
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests