Skip to content

Instantly share code, notes, and snippets.

@ripter
Created December 13, 2012 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripter/4274146 to your computer and use it in GitHub Desktop.
Save ripter/4274146 to your computer and use it in GitHub Desktop.
Zwoptex template for Löve2D
-- SpriteSheet
-- Handles custom Zwoptex template: https://gist.github.com/4274146
module('SpriteSheet', package.seeall)
local SpriteSheet = {}
-- Loads and creates the sprite sheet from sheetName
function SpriteSheet:new(sheetName)
local ss = require(sheetName)
setmetatable(ss, { __index = self })
return ss
end
function SpriteSheet:draw(name, x, y, r, sx, sy, ox, oy, kx, ky )
love.graphics.drawq( self.image, self.frames[name].quad, x, y, r, sx, sy, ox, oy, kx, ky )
end
return SpriteSheet
module('{{ metadata.target.textureFileName }}', package.seeall)
-- This file is for use with Löve2d and was generated by Zwoptex (http://zwoptexapp.com/)
--
-- This is an extremely simple conversion.
-- Format written by Chris Richards.
local fileName = '{{ metadata.target.textureFileName}}{{ metadata.target.textureFileExtension }}'
local sheet = {
fileName = fileName
, image = love.graphics.newImage(fileName)
, frames = {
{% for sprite in sprites %}
{{ sprite.nameWithoutExtension }} = {
quad = love.graphics.newQuad({{ sprite.textureRectX }}, {{ sprite.textureRectY }}, {{ sprite.textureRectWidth }}, {{ sprite.textureRectHeight }}, {{ metadata.sizeWidth }}, {{ metadata.sizeHeight }})
, name = "{{ sprite.nameWithoutExtension }}"
, rect = { x = {{ sprite.textureRectX }}, y = {{ sprite.textureRectY }}, width = {{ sprite.textureRectWidth }}, height = {{ sprite.textureRectHeight }} }
},
{% /for %}
}
}
return sheet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment