Skip to content

Instantly share code, notes, and snippets.

@aronmeza aronmeza/data.lua
Created Aug 1, 2014

Embed
What would you like to do?
Efectos de cambio de escena - CoronaLabs - Nituniyo
--Clase para manejar los datos del usuario
-- que se estarán pasando entre escenas
local M = { } --tabla vacia
return M
--imports para las crear escenas
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local widget = require( "widget" )
local data = require("data")
--Con suffix podemos saber si la pantalla es de alta resolucion
--local suffix= display.imageSuffix
----------------------------------------------------------------------------------
--
-- NOTE:
--
-- Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
---------------------------------------------------------------------------------
-- local forward references should go here --
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local buttonPlayer=nil
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- Function to handle button events
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
print(data.paramEffect .. "aaaaa")
local options =
{
effect = data.paramEffect,
time = 1800,
params = { var1 = "custom", myVar = "another" } --Variables que se desean pasar a la siguiente escena por medio del eventListener. La información puede ser accesada mediante event.params dentro de "createScene", "willEnterScene" y "enterScene" de la siguiente escena
}
storyboard.purgeScene("intro")
storyboard.gotoScene( "intro2", options )
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
print("createScene")
print(data.level)
print(data.paramEffect)
local intro = display.newImage("nituniyo-intro-android.png")
intro.x=centerX
intro.y=centerY
group:insert(intro)
if data.level ==1 then data.paramEffect ="fade" elseif
data.level== 2 then data.paramEffect ="zoomOutIn" elseif
data.level== 3 then data.paramEffect ="zoomOutInFade" elseif
data.level== 4 then data.paramEffect ="zoomInOut" elseif
data.level== 5 then data.paramEffect ="zoomInOutFade" elseif
data.level== 6 then data.paramEffect ="flip" elseif
data.level== 7 then data.paramEffect ="flipFadeOutIn" elseif
data.level== 8 then data.paramEffect ="zoomOutInRotate" elseif
data.level== 9 then data.paramEffect ="zoomOutInFadeRotate" elseif
data.level== 10 then data.paramEffect ="zoomInOutRotate" elseif
data.level== 11 then data.paramEffect ="fromRight" elseif
data.level== 12 then data.paramEffect ="fromLeft" elseif
data.level== 13 then data.paramEffect ="fromTop" elseif
data.level== 14 then data.paramEffect ="fromBottom" elseif
data.level== 15 then data.paramEffect ="slideLeft" elseif
data.level== 16 then data.paramEffect ="slideRight" elseif
data.level== 17 then data.paramEffect ="slideDown" elseif
data.level== 18 then data.paramEffect ="slideUp" elseif
data.level== 19 then data.paramEffect ="crossFade"
end
data.level=data.level+1
-- Create the widget
local button1 = widget.newButton
{
label = data.paramEffect,
onEvent = handleButtonEvent,
emboss = false,
--properties for a rounded rectangle button...
shape="roundedRect",
width = 200,
height = 40,
cornerRadius = 2,
fillColor = { default={ 119, 119, 119, 1 }, over={ 119, 119, 119, 0.4 } },
strokeColor = { default={ 0, 0, 0, 1 }, over={ 0, 0, 0, 1 } },
strokeWidth = 4
}
-- Center the button
button1.x = display.contentCenterX
button1.y = display.contentCenterY+100
group:insert(button1)
-----------------------------------------------------------------------------
-- CREATE display objects and add them to 'group' here.
-- Example use-case: Restore 'group' from previously saved state.
-----------------------------------------------------------------------------
end
-- Called BEFORE scene has moved onscreen:
function scene:willEnterScene( event )
local group = self.view
print("willEnterScene")
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print("enterScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-----------------------------------------------------------------------------
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print("exitScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
-----------------------------------------------------------------------------
end
-- Called AFTER scene has finished moving offscreen:
function scene:didExitScene( event )
local group = self.view
print("didExitScene")
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print("destroyScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. remove listeners, widgets, save state, etc.)
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
print("overlayBegan")
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
print("overlayEnded")
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "willEnterScene" event is dispatched before scene transition begins
scene:addEventListener( "willEnterScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "didExitScene" event is dispatched after scene has finished transitioning out
scene:addEventListener( "didExitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-- "overlayBegan" event is dispatched when an overlay scene is shown
scene:addEventListener( "overlayBegan", scene )
-- "overlayEnded" event is dispatched when an overlay scene is hidden/removed
scene:addEventListener( "overlayEnded", scene )
---------------------------------------------------------------------------------
return scene
--imports para las crear escenas
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local widget = require( "widget" )
local data = require("data")
--Con suffix podemos saber si la pantalla es de alta resolucion
--local suffix= display.imageSuffix
----------------------------------------------------------------------------------
--
-- NOTE:
--
-- Code outside of listener functions (below) will only be executed once,
-- unless storyboard.removeScene() is called.
--
---------------------------------------------------------------------------------
-- local forward references should go here --
local centerX = display.contentCenterX
local centerY = display.contentCenterY
local buttonPlayer=nil
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- Function to handle button events
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
print(data.paramEffect .. "aaaaa")
local options =
{
effect = data.paramEffect,
time = 1800,
params = { var1 = "custom", myVar = "another" } --Variables que se desean pasar a la siguiente escena por medio del eventListener. La información puede ser accesada mediante event.params dentro de "createScene", "willEnterScene" y "enterScene" de la siguiente escena
}
storyboard.purgeScene("intro2")
storyboard.gotoScene( "intro", options )
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
print("createScene")
print(data.level)
print(data.paramEffect)
local intro = display.newImage("nituniyo-intro-android.png")
intro.x=centerX
intro.y=centerY
group:insert(intro)
if data.level ==1 then data.paramEffect ="fade" elseif
data.level== 2 then data.paramEffect ="zoomOutIn" elseif
data.level== 3 then data.paramEffect ="zoomOutInFade" elseif
data.level== 4 then data.paramEffect ="zoomInOut" elseif
data.level== 5 then data.paramEffect ="zoomInOutFade" elseif
data.level== 6 then data.paramEffect ="flip" elseif
data.level== 7 then data.paramEffect ="flipFadeOutIn" elseif
data.level== 8 then data.paramEffect ="zoomOutInRotate" elseif
data.level== 9 then data.paramEffect ="zoomOutInFadeRotate" elseif
data.level== 10 then data.paramEffect ="zoomInOutRotate" elseif
data.level== 11 then data.paramEffect ="fromRight" elseif
data.level== 12 then data.paramEffect ="fromLeft" elseif
data.level== 13 then data.paramEffect ="fromTop" elseif
data.level== 14 then data.paramEffect ="fromBottom" elseif
data.level== 15 then data.paramEffect ="slideLeft" elseif
data.level== 16 then data.paramEffect ="slideRight" elseif
data.level== 17 then data.paramEffect ="slideDown" elseif
data.level== 18 then data.paramEffect ="slideUp" elseif
data.level== 19 then data.paramEffect ="crossFade"
end
data.level=data.level+1
-- Create the widget
local button1 = widget.newButton
{
label = data.paramEffect,
onEvent = handleButtonEvent,
emboss = false,
--properties for a rounded rectangle button...
shape="roundedRect",
width = 200,
height = 40,
cornerRadius = 2,
fillColor = { default={ 119, 119, 119, 1 }, over={ 119, 119, 119, 0.4 } },
strokeColor = { default={ 0, 0, 0, 1 }, over={ 0, 0, 0, 1 } },
strokeWidth = 4
}
-- Center the button
button1.x = display.contentCenterX
button1.y = display.contentCenterY+100
group:insert(button1)
-----------------------------------------------------------------------------
-- CREATE display objects and add them to 'group' here.
-- Example use-case: Restore 'group' from previously saved state.
-----------------------------------------------------------------------------
end
-- Called BEFORE scene has moved onscreen:
function scene:willEnterScene( event )
local group = self.view
print("willEnterScene")
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
print("enterScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
-----------------------------------------------------------------------------
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
print("exitScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
-----------------------------------------------------------------------------
end
-- Called AFTER scene has finished moving offscreen:
function scene:didExitScene( event )
local group = self.view
print("didExitScene")
-----------------------------------------------------------------------------
-- This event requires build 2012.782 or later.
-----------------------------------------------------------------------------
end
-- Called prior to the removal of scene's "view" (display group)
function scene:destroyScene( event )
local group = self.view
print("destroyScene")
-----------------------------------------------------------------------------
-- INSERT code here (e.g. remove listeners, widgets, save state, etc.)
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is displayed via storyboard.showOverlay()
function scene:overlayBegan( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
print("overlayBegan")
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
-- Called if/when overlay scene is hidden/removed via storyboard.hideOverlay()
function scene:overlayEnded( event )
local group = self.view
local overlay_name = event.sceneName -- name of the overlay scene
print("overlayEnded")
-----------------------------------------------------------------------------
-- This event requires build 2012.797 or later.
-----------------------------------------------------------------------------
end
---------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "willEnterScene" event is dispatched before scene transition begins
scene:addEventListener( "willEnterScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "didExitScene" event is dispatched after scene has finished transitioning out
scene:addEventListener( "didExitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-- "overlayBegan" event is dispatched when an overlay scene is shown
scene:addEventListener( "overlayBegan", scene )
-- "overlayEnded" event is dispatched when an overlay scene is hidden/removed
scene:addEventListener( "overlayEnded", scene )
---------------------------------------------------------------------------------
return scene
local storyboard = require("storyboard") --librería para el manejo de niveles
--Información que se estará pasando entre pantallas
local data = require("data")
--declaración de datos que estaremos usando
data.score = 0
--opciones de como queremos que se comporten storyboard en los cambios de escenas
data.paramEffect = "fade"
local options =
{
effect = data.paramEffect,
time = 1800,
params = { var1 = "custom", myVar = "another" } --Variables que se desean pasar a la siguiente escena por medio del eventListener. La información puede ser accesada mediante event.params dentro de "createScene", "willEnterScene" y "enterScene" de la siguiente escena
}
data.level=1
--manda llamar a la escena para introducir el juego
storyboard.gotoScene( "intro" , options )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.