You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Example: Create and use an Animationrequire("animation")
functionnewImagePO2(filename)
localsource=love.image.newImageData(filename)
localw, h=source:getWidth(), source:getHeight()
-- Find closest power-of-two.localwp=math.pow(2, math.ceil(math.log(w)/math.log(2)))
localhp=math.pow(2, math.ceil(math.log(h)/math.log(2)))
-- Only pad if needed:ifwp~=worhp~=hthenlocalpadded=love.image.newImageData(wp, hp)
padded:paste(source, 0, 0)
returnlove.graphics.newImage(padded)
endreturnlove.graphics.newImage(source)
endfunctionlove.load()
-- Set a lovely pink background color.love.graphics.setBackgroundColor(0.96, 0.77, 0.87)
-- Load the source of the animation.img=newImagePO2("assets/anim-boogie.png")
-- Create an animation with a frame size of 32x32 and-- 0.1s delay betwen each frame.animation1=newAnimation(img, 32, 32, 0.1, 6)
endfunctionlove.update(dt)
-- The animation must be updated so it -- knows when to change frames.animation1:update(dt)
endfunctionlove.draw()
-- Draw the animation the center of the screen.animation1:draw(400, 300, 0, 1, 1)
end
The image source w and h are 96✖️64, but wp and hp become 128✖️64 after -- Find closest power-of-two. calculate。
assets/anim-boogie.png size doesn't right anymore.
fix to: can we just comment on the calculating part?
The good answer is (0 to frames -1 as said, -1 was forgot in the example), and use rowsize -1, else it will go from 0 to 3 instead of 0 to 2 at each line in the exemple. So:
for i = 0, frames - 1 do
local row = math.floor(i/rowsize)
local column = i%(rowsize -1)
Bug Show
it Twinkling
Fixing
We need to fix two files
examples/011_animation.lua
andanimation.lua
examples/011_animation.lua
source
The image source
w
andh
are 96✖️64, butwp
andhp
become 128✖️64 after-- Find closest power-of-two.
calculate。assets/anim-boogie.png
size doesn't right anymore.fix to: can we just comment on the calculating part?
animation.lua
source
Depending on
newAnimation(img, 32, 32, 0.1, 6)
example code above.frames == 6
, for 1 to 6(included).So, the row value will be
0 0 1 1 1 2
in the loopfor
. the processing like this:1:
local row = math.floor(0/3)
=>0
2: ...
3:
local row = math.floor(3/3)
=>1
...
6:
local row = math.floor(6/3)
=>2
Ending result just cut the 1st 32✖️32 png on the first row. lose one png in whole frames.
fix to
i = 0
andframes - 1
, so the loop from 0 to 5:End: row value
0 0 0 1 1 1
The text was updated successfully, but these errors were encountered: