Skip to content

Instantly share code, notes, and snippets.

@codepaladin
codepaladin / maskTransition.lua
Created January 14, 2015 19:28
Image Transitioning and Masking
local group = display.newGroup()
group:translate(display.contentCenterX, display.contentCenterY) -- move the group to the center of the screen
local baseImage = display.newImage(group, "base-image.png") -- draw the yellow circle image & add to group
local mask = graphics.newMask('example-mask.png') -- draw a mask
group:setMask(mask) -- set the mask on the group
transition.to( baseImage, { time=1000, x=180 } ) -- move the image
@codepaladin
codepaladin / PathMasking.lua
Last active August 29, 2015 14:13
Path Masking
local path = display.newImage( "Images/WorldMap/path/level2.png") -- base image (yellow line)
local mask = graphics.newMask( "Images/WorldMap/path/level2-mask-0.jpg" ) -- base mask (completely black)
path:setMask( mask )
local ctr = 0
local iterations = 38 -- number of mask images in animation sequence
local function mask( event )
ctr = ctr + 1
path:setMask( nil ) -- remove the previous mask
function zIndexCharacters()
local function redraw()
-- images are all held in an allImages array
for image = 1, #allImages do
allImages[image]:toBack()
end
end
local function compare( a, b )
return a.y > b.y
{
"unitType" : "ground",
"classType" : "melee",
"characterType" : "pc",
"allowableMoves" : 3,
"maxLife" : 50,
"animations":[
{
"baseSE":
{
local sheetInfo = require("knight")
local myImageSheet = graphics.newImageSheet( "knight.png", sheetInfo:getSheet())
local sequenceData =
{
name="rotate",
start=1,
count=8,
time=1000,
@codepaladin
codepaladin / config.lua
Created June 24, 2014 20:21
Config File
-- taken from http://coronalabs.com/blog/2013/09/10/modernizing-the-config-lua/
--calculate the aspect ratio of the device
local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio > 1.5 and 800 or math.ceil( 1200 / aspectRatio ),
height = aspectRatio < 1.5 and 1200 or math.ceil( 800 * aspectRatio ),
scale = "letterBox",
fps = 30,
-- update the damage bar
function updateDamageBar()
damageBar.x = currentHealth / 2
damageBar.width = maxHealth - currentHealth
end
-- lower the character's currentHealth
function damageCharacter(damageTaken)
currentHealth = currentHealth - damageTaken
updateDamageBar()
-- create green health bar
healthBar = display.newRect(0,
-45,
maxHealth,
10)
healthBar:setFillColor( 000/255, 255/255, 0/255 )
healthBar.strokeWidth = 1
healthBar:setStrokeColor( 255, 255, 255, .5 )
characterGroup:insert(healthBar)
-- add a group to contain the character and healthbar
characterGroup = display.newGroup( )
characterGroup.x = display.contentCenterX
characterGroup.y = display.contentCenterY
-- set maxHealth and currentHealth values
maxHealth = 100
currentHealth = 100
-- draw a character to the screen
-- find the path from point A to point B
function getPath()
-- create a Jumper Grid object by passing in our map table
local grid = Grid(map)
-- Creates a pathfinder object using Jump Point Search
local pather = Pathfinder(grid, 'JPS', walkable)
pather:setMode("ORTHOGONAL")
-- Calculates the path, and its length