Here’s my main if you wanna look at it :)
–
– main.lua
–
–Background Display
local background = display.newImage(“Graphics/skin.png”)
background.x = 240
background.y = 170
background:scale (0.6,0.6)
–SpriteSheet Setting
local sheetInfo = require “sprite”
local myImageSheet = graphics.newImageSheet(“Graphics/MarinSheet.png”,sheetInfo:getSheet())
local sequenceData = {
{name=“MarinAfly”, sheet = myImageSheet, start=sheetInfo:getFrameIndex(“MarinA_vole_01”),count=4,time=600,loopcount=0}
}
–Ennemy Display
–Mosqui = display.newSprite (myImageSheet,sequenceData)
–Mosqui.x = 250
–Mosqui.y = 250
–Mosqui:scale ( 0.6,0.6)
–Mosqui:setSequence(“MarinAfly”)
–Mosqui:play()
–Spawners
local spawnTimer
local spawnedObjects = {}
local spawnParams = {
xMin = 50,
xMax = 750,
yMin = 20,
yMax = 1100,
spawnTime = 200,
spawnOnTimer = 12,
spawnInitial = 4,
}
local function spawnItem (bounds)
local item = display.newSprite (myImageSheet,sequenceData)
item:setSequence(“MarinAfly”)
item:play()
item.x = math.random(bounds.xMin, bounds.xMax)
item.y = math.random(bounds.yMin, bounds.yMax)
spawnedObjects[#spawnedObjects+1] = item
end
local function spawnController(action, params)
if (spawnTimer and (action == “start” or action == “stop”))then
timer.cancel(spawnTimer)
end
if (action == “start”) then
local spawnBounds = {}
spawnBounds.xMin = params.xMin or 0
spawnBounds.xMAx = params.xMax or display.contentWidth
spawnBounds.yMin = params.yMin or 0
spawnBounds.yMax = params.yMax or display.contentHeight
local spawnTime = params.spawnTime or 1000
local spawnOnTimer = params.spawnOnTimer or 50
local spawnInitial = params.spawnInitial or 0
if (spawnInitial > 0) then
for n = 1, spawnInitial do
spawnItem(spawnBounds)
end
end
if (spawnOnTimer > 0) then
spawnTimer = timer.performWithDelay (spawnTime,function()spawnItem(spawnBounds); end,
spawnOnTimer)
end
elseif (action == “pause”) then
timer.pause(spawnTimer)
elseif (action == “resume”) then
timer.resume(spawnTimer)
end
end
spawnController(“start”,spawnParams)