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
hey, outstanding work! i found it pretty easy to add animations and sumneko lua annotations, wonder if you'd accept PRs to integrate them.
Example annotations
--- Maps given image name with the provided image.--- @paraminamestring The name of the image--- @paramurlstring? The url or reference to the image--- @overloadfun(iname: string, url?: love.Image)functioniffy.newImage(iname, url)
ifnoturlthenurl=inameiname=removeExtension(url)
endiffy.images[iname] =type(url) =='string' andlove.graphics.newImage(url) orurl--[[@as love.Image]]end
--- Makes a brand new sprite (image-quad) from given parameters.------ Before calling this function make sure you map iname with the image--- using newImage otherwise you won't be able to render the sprite with iffy--- @paraminamestring The name of the Image (needed to namespace the sprite)--- @paramnamestring The name of the Sprite (needed to locate the sprite)--- @paramxnumber The position of the sprite in the atlas--- @paramynumber The width of the sprite--- @paramwidthnumber The width of the sprite--- @paramheightnumber Not needed if a reference (not url) to the image is provided--- @paramsw?number--- @paramsh?number--- @returnlove.Quadfunctioniffy.newSprite(iname, name, x, y, width, height, sw, sh)
localimage=iffy.images[iname]
ifnotswandnotimagethenerror("Iffy Error! " .."You must provide the size of the image in the last parameter " .."in the function 'newSprite'"
)
endifnotswthensw=image:getWidth()
endifnotshthensh=image:getHeight()
endifnotiffy.spritesheets[iname] theniffy.spritesheets[iname] = {} endifnotiffy.spritedata[iname] theniffy.spritedata[iname] = {} endiffy.spritesheets[iname][name] =love.graphics.newQuad(x, y, width, height, sw, sh)
table.insert(iffy.spritedata[iname], { name, x, y, width, height })
returniffy.spritesheets[iname][name]
end
IDE screenshots with annotations
Basic Animation module
localAtlas=require"src.tool.atlas"localAnimation= {}
---@paramnamestring an identifier for the animation---@paramatlasstring the name of the atlas to use, loaded from iffy---@paramframestable<number, string> a table of frame numbers and sprite names, mapped to the atlas defined keys---@paramfpsnumber the number of frames per second to play---@paramloopboolean whether or not to loop the animationfunctionAnimation.new(name, atlas, frames, fps, loop)
localself= {}
self.name=nameself.atlas=atlasself.frames=framesself.fps=fpsself.loop=loopself.currentFrame=1self.currentTime=0functionself.update(dt)
ifdt>0.1then-- clamp to prevent the animation from updating too quickly and freezing the gamedt=0.1endself.currentTime=self.currentTime+dtifself.currentTime>=1/self.fpsthenself.currentTime=self.currentTime-1/self.fpsself.currentFrame=self.currentFrame+1ifself.currentFrame>#self.framesthenifself.loopthenself.currentFrame=1elseself.currentFrame=#self.framesendelseifself.currentFrame<1thenifself.loopthenself.currentFrame=#self.frameselseself.currentFrame=1endendendendfunctionself.draw(x, y, r, sx, sy)
Atlas.lib.drawSprite(self.frames[self.currentFrame], x, y, r, sx, sy) -- Atlas.lib = iffyendreturnselfendreturnAnimation
Usage
localAtlas=require"src.tool.atlas"localAnimation=require"src.tool.animation"localrandom_npc_reward= {}
functionlove.load()
love.graphics.setDefaultFilter("nearest", "nearest")
Atlas.Export() -- generates assets/main_atlas.xmlAtlas.Load() -- loads assets/main_atlas.xml into memory, `main_atlas` is now availablerandom_npc_reward=Animation.new("random_npc_reward", "main_atlas", {
[1] ="npc_merchant",
[2] ="npc_knight",
[3] ="npc_kid",
}, 6, true)
endfunctionlove.draw()
random_npc_reward.draw(200, 200, 0, 4, 4)
endfunctionlove.update(dt)
random_npc_reward.update(dt)
end
Let me know your thoughts. I'm picking iffy because of how scalable I think this library is, others are way too opinionated and not flexible enough.
Also noticed the license is missing
The text was updated successfully, but these errors were encountered:
hey, outstanding work! i found it pretty easy to add animations and sumneko lua annotations, wonder if you'd accept PRs to integrate them.
Example annotations
IDE screenshots with annotations
Basic Animation module
Usage
Let me know your thoughts. I'm picking iffy because of how scalable I think this library is, others are way too opinionated and not flexible enough.
Also noticed the license is missing
The text was updated successfully, but these errors were encountered: