改变lua corona sdk hellp pleaSE中的场景 [英] change scene in lua corona sdk hellp pleaSE

查看:98
本文介绍了改变lua corona sdk hellp pleaSE中的场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我创造了一个游戏,用户必须匹配屏幕上的按钮。屏幕上包含网格上的12个按钮,这些按钮都运行良好。我的问题是,当用户匹配所有按钮时,我想将场景更改为名为congrats的场景。我现在很困难,因为我不知道如何或在哪里改变场景,当他们的屏幕上没有任何按钮时,有人可以播放吗?



本地storyboard = require(  storyboard
local scene = storyboard.newScene()
physics = require( physics
physics .start()
physics.setGravity( 0 9 8
- 设置全局宽度和高度变量
_W = display.contentWidth;
_H = display.contentHeight;
- 隐藏状态栏
display.setStatusBar(display.HiddenStatusBar);
--Declare一个totalButtons变量来跟踪屏幕上的按钮数量
local totalButtons = 0
--Declare变量跟踪按钮select
local secondSelect = 0
local checkForMatch = false
- 设置游戏功能
功能游戏(对象, event)
if (event.phase == 开始)然后
if (checkForMatch == false and secondSelect == 0 )然后
- 翻转第一个按钮
buttonCover [object.number] .isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true)then b b b if (secondSelect == < span class =code-digit> 0 )然后
- 翻译第二个按钮
buttonCover [object.number] .isVisible = false;
secondSelect = 1 ;
- 如果按钮执行不匹配,则翻转按钮超过
if (lastButton .myName~ = object.myName)然后
matchText.text = 找不到匹配!;
timer.performWithDelay( 1250 ,function()
matchText.text = ;
checkForMatch = false;
secondSelect = 0 ;
buttonCover [lastButton.number] .isVisible = true;
buttonCover [object.number] .isVisible = true;
end, 1
- 如果按钮匹配,删除按钮
elseif(lastButton.myName == object.myName)然后
matchText.text = 找到匹配!;
timer.performWithDelay( 1250 ,function()
matchText.text = ;
checkForMatch = false;
secondSelect = 0 ;
physics.addBody(lastButton,{density = 2 0 ,friction = 1 5 ,反弹= 0. 0 })
physics.addBody(object,{density = 2 0 ,friction = 1 5 ,反弹= 0. 0 })
lastButton:removeSelf();
object:removeSelf();
buttonCover [lastButton.number]:removeSelf();
buttonCover [object.number]:removeSelf();
结束, 1
结束
结束
结束
结束
结束
功能场景: createScene( event)
local screenGroup = self .view
--Declare button,buttonCover和buttonImages table
button = {}
--screenGroup:insert(button)
buttonCover = {}
--screenGroup:insert(buttonCover)
buttonImages = { 1 1 2 2 3 3 4 ,< span class =code-digit> 4 , 5 5 6 6 }
--screenGroup:insert(buttonImages)
--Declare and prime最后一个按钮选择变量
lastButton = display.newImage( 1.png);
lastButton.myName = 1 ;
screenGroup:insert(lastButton)
- 设置简单的灰白色背景
myRectangle = display.newRect( 0 ,< span class =code-digit> 0 ,_ W,_ H)
myRectangle:setFillColor( 235 235 235
screenGroup:insert(myRectangle)
--Notify player if 匹配符号
matchText = display.newText( 0 0 ,native.systemFont, 26
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor( 0 0 0
matchText.x = _W / 2
screenGroup:insert(matchText)
- - 屏幕上的按钮
for count = 1 3 执行
x = x + 90
y = 20
for insideCount = 1 4 < span class =code-keyword> do
y = y + 90
- 将每个图像分配到网格上的随机位置
temp = math.random( 1 ,#buttonImages)
button [count] = display.newImage(buttonImages [temp] .. 。png);
- 按钮
按钮[count] .x = x;
按钮[count] .y = y;
- 给每个按钮一个名字
按钮[count] .myName = buttonImages [temp]
按钮[count] .number = totalButtons
- ]]
- 从buttonImages表中删除按钮
table.remove(buttonImages,temp)
- 设置封面以隐藏按钮图像
buttonCover [totalButtons] = display.newImage( button.png);
buttonCover [totalButtons] .x = x; buttonCover [totalButtons] .y = y;
totalButtons = totalButtons + 1
- 每个按钮的听众事件
按钮[count] .touch = game
按钮[count]:addEventListener( touch,按钮[count])
end
结束
print( \ n1:createScene event
结束
函数场景:enterScene(事件)
结束
函数场景:exitScene(事件)
结束
函数场景:destroyScene(事件)
结束
场景:addEventListener( createScene,场景)
场景:addEventListener ( enterScene,scene)
场景:addEventListener( exitScene,scene)
scene:addEventListener(< / code> destroyScene,场景)
返回场景





当所有按钮都从屏幕上删除后,我会让我的应用改变场景。



谢谢

解决方案

您更有可能在 http://www.coronalabs获得良好帮助.com / products / corona-sdk / [ ^ ]。

hi i have created game where a user will have to match buttons on the screen. The screen contains 12 buttons on a grid which all work well. My Problem is that i want to change the scene to a scene named "congrats" when the user matches all the buttons . I am currently having difficult with as i don''t how or where to change scene when their is no buttons left on the screen can someone me plz?

local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
physics = require("physics")
physics.start()
physics.setGravity(0, 9.8)
--Set Global width and height variables
_W = display.contentWidth;
_H = display.contentHeight;
--Hide status bar
display.setStatusBar(display.HiddenStatusBar);
--Declare a totalButtons variable to track number of buttons on screen
local totalButtons = 0
--Declare variable to track button select
local secondSelect = 0
local checkForMatch = false
--Set up game function
function game(object, event)
if(event.phase == "began") then
if(checkForMatch == false and secondSelect == 0) then
--Flip over first button
buttonCover[object.number].isVisible = false;
lastButton = object
checkForMatch = true
elseif(checkForMatch == true) then
if(secondSelect == 0) then
--Flip over second button
buttonCover[object.number].isVisible = false;
secondSelect = 1;
--If buttons do not match, flip buttons over
if(lastButton.myName ~= object.myName) then
matchText.text = "Match Not Found!";
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
buttonCover[lastButton.number].isVisible = true;
buttonCover[object.number].isVisible = true;
end, 1)
--If buttons DO match, remove buttons
elseif(lastButton.myName == object.myName) then
matchText.text = "Match Found!";
timer.performWithDelay(1250, function()
matchText.text = " ";
checkForMatch = false;
secondSelect = 0;
physics.addBody(lastButton, {density = 2.0, friction = 1.5, bounce=0.0})
physics.addBody(object, {density = 2.0, friction = 1.5, bounce=0.0})
lastButton:removeSelf();
object:removeSelf();
buttonCover[lastButton.number]:removeSelf();
buttonCover[object.number]:removeSelf();
end, 1)
end
end
end
end
end
function scene:createScene( event )
local screenGroup = self.view
--Declare button, buttonCover, and buttonImages table
button = {}
--screenGroup:insert( button )
buttonCover = {}
--screenGroup:insert( buttonCover )
buttonImages = {1,1, 2,2, 3,3, 4,4, 5,5,6,6}
--screenGroup:insert( buttonImages )
--Declare and prime a last button selected variable
lastButton = display.newImage("1.png");
lastButton.myName = 1;
screenGroup:insert( lastButton )
--Set up simple off-white background
myRectangle = display.newRect(0, 0, _W, _H)
myRectangle:setFillColor(235, 235, 235)
screenGroup:insert( myRectangle )
--Notify player if match is found or not
matchText = display.newText(" ", 0, 0, native.systemFont, 26)
matchText:setReferencePoint(display.CenterReferencePoint)
matchText:setTextColor(0, 0, 0)
matchText.x = _W/2
screenGroup:insert( matchText )
--Place buttons on screen
for count = 1,3 do
x = x + 90
y = 20
for insideCount = 1,4 do
y = y + 90
--Assign each image a random location on grid
temp = math.random(1,#buttonImages)
button[count] = display.newImage(buttonImages[temp] .. ".png");
--Position the button
button[count].x = x;
button[count].y = y;
--Give each a button a name
button[count].myName = buttonImages[temp]
button[count].number = totalButtons
--]]
--Remove button from buttonImages table
table.remove(buttonImages, temp)
--Set a cover to hide the button image
buttonCover[totalButtons] = display.newImage("button.png");
buttonCover[totalButtons].x = x; buttonCover[totalButtons].y = y;
totalButtons = totalButtons + 1
--Attach listener event to each button
button[count].touch = game
button[count]:addEventListener( "touch", button[count] )
end
end
print( "\n1: createScene event")
end
function scene:enterScene( event )
end
function scene:exitScene( event )
end
function scene:destroyScene( event )
end
scene:addEventListener( "createScene", scene )
scene:addEventListener( "enterScene", scene )
scene:addEventListener( "exitScene", scene )
scene:addEventListener(</code> "destroyScene", scene )
return scene



when all the buttons have been removed from the screen, I would my app to change scene.

Thank You

解决方案

You are more likely to get good help at http://www.coronalabs.com/products/corona-sdk/[^].


这篇关于改变lua corona sdk hellp pleaSE中的场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆