Skip to content

Instantly share code, notes, and snippets.

@codepaladin
codepaladin / maskTransition.lua
Created Jan 14, 2015
Image Transitioning and Masking
View maskTransition.lua
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
View PathMasking.lua
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
View z-index.lua
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
View dwarf.json
{
"unitType" : "ground",
"classType" : "melee",
"characterType" : "pc",
"allowableMoves" : 3,
"maxLife" : 50,
"animations":[
{
"baseSE":
{
View image-scaling.lua
local sheetInfo = require("knight")
local myImageSheet = graphics.newImageSheet( "knight.png", sheetInfo:getSheet())
local sequenceData =
{
name="rotate",
start=1,
count=8,
time=1000,
View config.lua
-- 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,
View healthBarFunctions.lua
-- 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()
View healthBarDisplay.lua
-- 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)
View healthBarSetup.lua
-- 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
View iso-getPath.lua
-- 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