Are you using anim8 for animation?
-
- Prole
- Posts: 12
- Joined: Sat Oct 21, 2023 1:33 pm
Are you using anim8 for animation?
I am learning animation with anim8.I know about grid,animation.I code in a way that it plays infinite loop with true or false value.I want to how how to set in such a way to perform animation for once.Can anyone share sample anim8 frame project with me ?I want to learn the basic of frames and key events
-
- Prole
- Posts: 12
- Joined: Sat Oct 21, 2023 1:33 pm
Re: Are you using anim8 for animation?
Here is sample code.I hoping someone to help
_G.love = require("love")
function love.load()
ani8 = require("lib.anim8.anim8")
player = {}
player.x = 100
player.y = 100
player.image = love.graphics.newImage('assets/spritesheet.png')
player.grid = ani8.newGrid(332,275,2656,1925)
-- player.animation = ani8.newAnimation(player.grid('1-8',1),0.2)
player.frame = player.grid('1-7',2)
player.animation = ani8.newAnimation(player.frame ,0.2)
-- 2,656 × 1,925
go = false;
end
function love.update(dt)
player.animation:update(dt)
if love.keyboard.isDown("d") then
go = true
end
end
function love.draw()
if go then
player.animation:draw(player.image,100 ,100)
end
end
_G.love = require("love")
function love.load()
ani8 = require("lib.anim8.anim8")
player = {}
player.x = 100
player.y = 100
player.image = love.graphics.newImage('assets/spritesheet.png')
player.grid = ani8.newGrid(332,275,2656,1925)
-- player.animation = ani8.newAnimation(player.grid('1-8',1),0.2)
player.frame = player.grid('1-7',2)
player.animation = ani8.newAnimation(player.frame ,0.2)
-- 2,656 × 1,925
go = false;
end
function love.update(dt)
player.animation:update(dt)
if love.keyboard.isDown("d") then
go = true
end
end
function love.draw()
if go then
player.animation:draw(player.image,100 ,100)
end
end
Re: Are you using anim8 for animation?
https://github.com/kikito/anim8
local animation = anim8.newAnimation(frames, durations, onLoop)
onLoop is an optional parameter which can be a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops". It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
local animation = anim8.newAnimation(frames, durations, onLoop)
onLoop is an optional parameter which can be a function or a string representing one of the animation methods. It does nothing by default. If specified, it will be called every time an animation "loops". It will have two parameters: the animation instance, and how many loops have been elapsed. The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
-
- Prole
- Posts: 12
- Joined: Sat Oct 21, 2023 1:33 pm
Re: Are you using anim8 for animation?
How do you handle animation?I handle with true or false.But it is not a good way.Because It repeats everytime .
I cloned your strike project:
In the assets
IMAGE[enum.imageSheetBattleshipSinking] = love.graphics.newImage("assets/images/battleshipsinkingsheet.png")
F
The picture is missing.
I cloned your strike project:
In the assets
IMAGE[enum.imageSheetBattleshipSinking] = love.graphics.newImage("assets/images/battleshipsinkingsheet.png")
F
The picture is missing.
Re: Are you using anim8 for animation?
I used anim8 for a very long time while learning love. I then realised I could roll my own animations by tracking some very simple properties and quads:
- which frame to show
- how quickly to change frames
- how much time is left on this frame
- how many frames in total
- should this loop?
And then basic draw data you need for normal images: X, y, rotation etc.
Anim8 has limitations (all libraries do) so this wasn't hard and gives me options.
Sorry about that missing image. I'm usually very disciplined that way. For testing purposes just use the file name
destroyersinkingsheet.png
- which frame to show
- how quickly to change frames
- how much time is left on this frame
- how many frames in total
- should this loop?
And then basic draw data you need for normal images: X, y, rotation etc.
Anim8 has limitations (all libraries do) so this wasn't hard and gives me options.
Sorry about that missing image. I'm usually very disciplined that way. For testing purposes just use the file name
destroyersinkingsheet.png
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Re: Are you using anim8 for animation?
You can see here I create a flame animation and add it to the animation table. Futher down I draw all animations on the animation table in a generic way.
During the update I do two things: reposition the animation because they are sometimes overlaid on top of a moving image and then decrease the timer so I know when to 'kill' the animation by removing it from the animation table.
Simples.
During the update I do two things: reposition the animation because they are sometimes overlaid on top of a moving image and then decrease the timer so I know when to 'kill' the animation by removing it from the animation table.
Simples.
Code: Select all
function functions.addFlameAnimation(x, y, facingrad)
-- flame animation
local newanim = {}
newanim.imageenum = enum.imageSheetSmokeFire -- only the enum
newanim.startframe = 9
newanim.stopframe = 16
newanim.linkobj = nil
newanim.x = x
newanim.y = y
newanim.speed = 0.25 -- seconds per frame
newanim.rotation = facingrad -- radians
newanim.currentframe = newanim.startframe
newanim.timeleft = newanim.speed -- how much time left on this frame
newanim.kill = false
table.insert(ANIMATIONS, newanim)
end
function functions.animationsdraw()
love.graphics.setColor(1,1,1,1)
for k, anim in pairs(ANIMATIONS) do
-- calculate the offset
local xoffset, yoffset
if anim.xoffset == nil then
xoffset = FRAMES[anim.imageenum].width / 2
else
xoffset = anim.xoffset
end
if anim.yoffset == nil then
yoffset = FRAMES[anim.imageenum].height / 2
else
yoffset = anim.yoffset
end
love.graphics.draw(IMAGE[anim.imageenum], FRAMES[anim.imageenum][anim.currentframe], anim.x, anim.y, anim.rotation, anim.xscale, anim.yscale, xoffset, yoffset)
end
end
function functions.animationsupdate(dt)
-- update all animations
for i = #ANIMATIONS, 1, -1 do
if ANIMATIONS[i].kill == true then
table.remove(ANIMATIONS, i)
else
-- update the position of the animation if it is attached to a moving object
if ANIMATIONS[i].linkobj ~= nil then
obj = ANIMATIONS[i].linkobj
if obj.physobj ~= nil then
local objfacing = obj.physobj.body:getAngle() -- rads
local x, y = obj.physobj.body:getPosition()
ANIMATIONS[i].x = x
ANIMATIONS[i].y = y
ANIMATIONS[i].rotation = objfacing + math.pi / 2 -- rads. 90 deg = pi / 2
end
end
ANIMATIONS[i].timeleft = ANIMATIONS[i].timeleft - dt
if ANIMATIONS[i].timeleft <= 0 then -- advance to the next frame
ANIMATIONS[i].currentframe = ANIMATIONS[i].currentframe + 1
ANIMATIONS[i].timeleft = ANIMATIONS[i].speed
if ANIMATIONS[i].currentframe > ANIMATIONS[i].stopframe then
if ANIMATIONS[i].endless then
ANIMATIONS[i].currentframe = ANIMATIONS[i].startframe
else
table.remove(ANIMATIONS, i)
end
end
end
end
end
end
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Who is online
Users browsing this forum: Google [Bot] and 6 guests