Thanks Brent. So here we go:
Basically on game.lua there is an animation of a rect growing upwards, then I show the ad on gameOver.lua. If you keep going back and forth between game.lua and gameOver.lua, after about 15 times, it starts getting really laggy. Also, xcode throws some errors, especially this one: <Error>: CoreAnimation: failed to allocate IOSurface.
main.lua
[lua]
display.setStatusBar( display.HiddenStatusBar )
local composer = require “composer”
local fbAudienceNetwork = require “plugin.fbAudienceNetwork”
local placementID = “891399177635872_891878497587940”
local adSize = “BANNER_HEIGHT_50”
local function adListener( event )
if ( event.phase == “init” ) then – Successful initialization
print( event.type )
elseif ( event.phase == “loaded” ) then – The ad was successfully loaded
print( event.type )
print( event.placementId )
– Show the ad
fbAudienceNetwork.show( “banner”, placementID, {y = 0} )
elseif ( event.phase == “failed” ) then – The ad failed to load
end
end
– Initialize the Facebook Audience Network
fbAudienceNetwork.init( adListener , {“8c57c3feea536ab65c40b5958b71b409ed55ed47”, “36eabd3c0b5e6d63236e74f0911f5353674fe4dd”})
composer.gotoScene( “game” )
[/lua]
game.lua
[lua]
local composer = require “composer”
local scene = composer.newScene()
– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.
– local forward references should go here
local bg, circle
local circleTransition
local function changeScene()
composer.gotoScene( “gameOver” , “fade”, 150 )
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
– Initialize the scene here.
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
bg = display.newRect( sceneGroup , 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX, bg.anchorY = 0,0
bg:setFillColor( 1,1,1,0.87 )
rect = display.newRect( sceneGroup, display.contentCenterX, display.contentHeight, display.contentWidth, 20 )
rect.anchorY = 1
rect:setFillColor( 1,.8,0 )
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen).
circleTransition = transition.to( circle, {radius = 1000, time = 3000} )
elseif ( phase == “did” ) then
– Called when the scene is now on screen.
– Insert code here to make the scene come alive.
– Example: start timers, begin animation, play audio, etc.
rect.width = display.contentWidth
rect.height = 20
rectTransition = transition.to( rect, { height = display.contentHeight, time = 3000, tag=“trans”, onComplete=changeScene} )
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen).
– Insert code here to “pause” the scene.
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen.
transition.cancel( “trans” )
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s view (“sceneGroup”).
– Insert code here to clean up the scene.
– Example: remove display objects, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
gameOver.lua
[lua]
local composer = require “composer”
local widget = require “widget”
local fbAudienceNetwork = require “plugin.fbAudienceNetwork”
local scene = composer.newScene()
– All code outside of the listener functions will only be executed ONCE unless “composer.removeScene()” is called.
– local forward references should go here
local placementID = “891399177635872_891878497587940”
local adSize = “BANNER_HEIGHT_50”
local bg
local button
local function onButtonRelease(event)
composer.gotoScene( “game” , “fade”, 150)
return true
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
– Initialize the scene here.
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
– Initialize the scene here.
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
bg = display.newRect( sceneGroup , 0, 0, display.contentWidth, display.contentHeight )
bg.anchorX, bg.anchorY = 0,0
bg:setFillColor( 0,.8,.5 )
button = widget.newButton( {
shape = “rect”,
label = “RESTART GAME”,
width = 220,
font = native.systemFontBold,
fontSize = 22,
fillColor = {default = {1,.8,0}, over = {1,.8,0,.5}},
labelColor = {default = {0}, over = {0,0,0,.5}},
onRelease = onButtonRelease
} )
button.anchorX = 0.5
button.anchorY = 0.5
button.x = display.contentCenterX
button.y = display.contentCenterY
sceneGroup:insert(button)
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == “did” ) then
– Called when the scene is now on screen.
– Insert code here to make the scene come alive.
– Example: start timers, begin animation, play audio, etc.
fbAudienceNetwork.load( “banner”, placementID, adSize )
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen).
– Insert code here to “pause” the scene.
– Example: stop timers, stop animation, stop audio, etc.
fbAudienceNetwork.hide( placementID )
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen.
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s view (“sceneGroup”).
– Insert code here to clean up the scene.
– Example: remove display objects, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]