Last active
January 26, 2017 13:33
-
-
Save PeterDwyer/03a781663a69763d5605 to your computer and use it in GitHub Desktop.
Texturepacker template for Corona to add support for sequencedata, based on the folder structure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- created with TexturePacker (http://www.codeandweb.com/texturepacker) | |
-- | |
-- {{smartUpdateKey}} | |
-- | |
-- local sheetInfo = require("mysheet") | |
-- local myImageSheet = graphics.newImageSheet( "mysheet.png", sheetInfo:getSheet() ) | |
-- local sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex("sprite")}} ) | |
-- | |
{% load filter %} | |
local SheetInfo = {} | |
SheetInfo.sheet = | |
{ | |
frames = {{% for sprite in allSprites %} | |
{ | |
x={{sprite.frameRect.x}}, | |
y={{sprite.frameRect.y}}, | |
width={{sprite.frameRect.width}}, | |
height={{sprite.frameRect.height}},{% if sprite.trimmed %} | |
sourceX = {{sprite.sourceRect.x}}, | |
sourceY = {{sprite.sourceRect.y}}, | |
sourceWidth = {{sprite.untrimmedSize.width}}, | |
sourceHeight = {{sprite.untrimmedSize.height}}{% endif %} | |
},{% endfor %} | |
}, | |
sheetContentWidth = {{texture.size.width}}, | |
sheetContentHeight = {{texture.size.height}} | |
} | |
SheetInfo.frameIndex = | |
{{% for sprite in allSprites %} | |
["{{sprite.trimmedName}}"] = {{ forloop.counter }},{% endfor %} | |
} | |
SheetInfo.sequenceData = | |
{{% for sprite in allSprites %}{% if sprite.trimmedName|IsNotCurrent %}}, | |
time=120 | |
}{% endif %}{% if sprite.trimmedName|CheckNotUsed %} | |
{ name={{sprite.trimmedName|GetSequenceName}}, | |
frames={ {% endif %} {{forloop.counter }}, {% if forloop.last %}}, | |
time=120 | |
}{% endif %}{% endfor %} | |
} | |
function SheetInfo:getSheet() | |
return self.sheet; | |
end | |
function SheetInfo:getFrameIndex(name) | |
return self.frameIndex[name]; | |
end | |
function SheetInfo:getSequenceData() | |
return self.sequenceData; | |
end | |
return SheetInfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<exporter version="1.0"> | |
<!-- identifier of the exporter --> | |
<name>corona-custom</name> | |
<!-- display name of the exporter for the combo box --> | |
<displayName>Corona SDK Custom</displayName> | |
<!-- description of the exporter --> | |
<description>Exporter for Corona SDK using image sheet format.</description> | |
<!-- exporter version --> | |
<version>1.0</version> | |
<!-- currently only one file allowed - more to come with update --> | |
<files> | |
<file> | |
<!-- name of this file variable --> | |
<name>lua</name> | |
<!-- human readable name (for GUI) --> | |
<displayName>Corona SDK lua file</displayName> | |
<!-- file extension for the file --> | |
<fileExtension>lua</fileExtension> | |
<!-- description what the file contains, used in tooltips in the GUI --> | |
<description>Lua file for CoronaSDK</description> | |
<!-- name of the template file --> | |
<template>corona-custom.lua</template> | |
</file> | |
</files> | |
<!-- target framework supports trimming --> | |
<supportsTrimming>true</supportsTrimming> | |
<!-- target framework supports rotated sprites --> | |
<supportsRotation>false</supportsRotation> | |
<!-- rotated sprites direction (cw/ccw) --> | |
<rotationDirection>cw</rotationDirection> | |
<!-- supports npot sizes --> | |
<supportsNPOT>true</supportsNPOT> | |
<!-- supports file name stripping (remove .png etc) --> | |
<supportsTrimSpriteNames>yes</supportsTrimSpriteNames> | |
<!-- supports texure subpath --> | |
<supportsTextureSubPath>yes</supportsTextureSubPath> | |
</exporter> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
previousSequenceName = ""; | |
currentSequenceName = ""; | |
var CheckNotUsed = function(input) | |
{ | |
var rawInput = input.rawString(); | |
var tempName = rawInput.split("/"); | |
currentSequenceName = tempName[0] | |
if( previousSequenceName == "" ) | |
{ | |
previousSequenceName = currentSequenceName; | |
return "true"; | |
} | |
else if( previousSequenceName == currentSequenceName ) | |
{ | |
return ""; | |
} | |
else | |
{ | |
previousSequenceName = currentSequenceName; | |
return "true"; | |
} | |
return ""; // return empty string | |
}; | |
CheckNotUsed.filterName = "CheckNotUsed"; | |
Library.addFilter("CheckNotUsed"); | |
var GetSequenceName = function(input) | |
{ | |
return currentSequenceName; // perform calculation, return result as string | |
}; | |
GetSequenceName.filterName = "GetSequenceName"; | |
Library.addFilter("GetSequenceName"); | |
var IsNotCurrent = function(input) | |
{ | |
var rawInput = input.rawString(); | |
var tempName = rawInput.split("/"); | |
tempSequenceName = tempName[0] | |
if( currentSequenceName == "" ) | |
{ | |
return ""; | |
} | |
else if( currentSequenceName == tempSequenceName ) | |
{ | |
return ""; | |
} | |
return "true" // perform calculation, return result as string | |
}; | |
IsNotCurrent.filterName = "IsNotCurrent"; | |
Library.addFilter("IsNotCurrent"); |
Updated the exporter to use the folder name attached to the sprites so that the exporter will work with texture packer flash folders as well as physical hard drive folders.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This custom texture packer filter will take a texture packer sprite and output the corona ready lua file. It differs from the included corona imagesheet template in that it will take a folder structure and produce a sequence entry for each of the folders.
Note that the lowest level folder names are used to name the animation sequence and it defaults to having 140 as the runtime for the animation. but, updating the animation timing should be a far quicker job than hand entering all the folder name.
Note also that I may do a custom filter for flash based sprites as these get folders generated for them but, I currently get the folder name from the animations absolute path. This maye not work for flash animations and so the name will need to be retrieved another way.