Skip to content

Instantly share code, notes, and snippets.

@nadar71
Forked from PeterDwyer/corona-custom.lua
Created January 26, 2017 13:33
Show Gist options
  • Save nadar71/a3015e9da42330d9a3ff8918b89a39e1 to your computer and use it in GitHub Desktop.
Save nadar71/a3015e9da42330d9a3ff8918b89a39e1 to your computer and use it in GitHub Desktop.
Texturepacker template for Corona to add support for sequencedata, based on the folder structure.
-- 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
<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>
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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment