2012-04-04 18 views
0

私はゲーム開発が初めてで、私の現在のプロジェクト用の単純なGUIフレームワークを作成しようとしています。私は現在、シーン管理のためにDirectorクラス1.4を使用しています。自分のプロジェクトのシーンを変更しましたが、今はポップアップウィンドウを作成したいと思います。私はちょうど私の現在のシーン上に表示するポップアップウィンドウをしたい。以下は私のmain.luaとmenu.lua(私の最初のシーン)のコードです。もし誰かが私を助けてくれたら、本当に感謝します。私はコロナとプログラミング全般について非常に新しいので、できるだけ具体的にしてください。コロナSDK - ポップアップウィンドウ(Directorクラスを使用)

main.lua

_W = display.contentWidth 
_H = display.contentHeight 

local director = require ("director"); 

local mainGroup = display.newGroup(); 

local function main() 

mainGroup:insert(director.directorView); 

director:changeScene("menu"); 

return true; 
end 

main(); 

menu.lua

module(..., package.seeall) 

function new() 
    local localGroup = display.newGroup(); 

    local bg = display.newImage("Images/background1.PNG"); 

    local myText = display.newText("Merchant", 0, 0, native.systemFont, 24) 
    myText:setTextColor(255, 255, 255) 
    myText:setReferencePoint(display.CenterReferencePoint); 
    myText.x = _W/2; myText.y = _H/2; 

    local hero_btn = display.newImage("Images/weaponcraft.PNG", 25, 25); 
    hero_btn:setReferencePoint(display.BottomLeftReferencePoint); 
    hero_btn.x = 252; hero_btn.y = 475; 
    hero_btn.scene = "heroMain"; 

    local craft_btn = display.newImage("Images/smithing.PNG", 25, 25); 
    craft_btn:setReferencePoint(display.BottomLeftReferencePoint); 
    craft_btn.x = 7; craft_btn.y = 475; 
    craft_btn.scene = "craftMain"; 

    local inventory_btn = display.newImage("Images/inventory1.png"); 
    inventory_btn:setReferencePoint(display.CenterReferencePoint); 
    inventory_btn.x = _W/2; inventory_btn.y = 430; 
    --inventory_btn.scene = "inventory"; 

    function changeScene(e) 
     if(e.phase == "ended") then 
      director:changeScene(e.target.scene); 
     end 
    end  

    localGroup:insert(bg); 
    localGroup:insert(hero_btn); 
    localGroup:insert(craft_btn); 

    hero_btn:addEventListener("touch", changeScene); 
    craft_btn:addEventListener("touch", changeScene); 

    return localGroup; 
end 

答えて

0

あなたはnative.showAlert機能を使用することができます。これは、ポップアップダイアログボックスを表示します。

このような何か:

local function onComplete(event) 

local action = event.action 
if "clicked" == event.action then 
    if 1 == event.index then 

    end 
end 

local alert = native.showAlert("You are in scene1!", "Congratulations!", { "OK" }, onComplete) 

このショー "あなたはSCENE1にいる!" とダイアログボックスタイトル、「おめでとう!サブタイトル、クリック(またはタップ)するとダイアログボックスを閉じる「OK」ボタンがあります。

これらのコードをシーンの前に置き、native.showAlertのプロパティを目的の単語に変更します。

0

カスタムポップアップを作成して、独自の方法で処理することができます。サンプルコードを入れています。

--function to create a dialog to be shown on the game over 
local function gameOverAlertScreen() 
    --Display item used in the popup screen 
    local alertBox , restartBtn, levelBtn, soundOnOffSwitch, quitOnOffSwitch, imageSheetSoundOnOff, imageSheetQuitOnOff 
    --initial constans used for positioning the display items 
    local startTX = -400 
    local startTY = halfH 
    local btnInitailY = halfH -50 
    local btnMargin = 10 

    --cancel the game pausse timer 
    if(gameTimer_main) then 
     timer.cancel(gameTimer_main) 
     gameTimer_main = nil 
    end 

    local optionSoundSheet = 
    { 
     -- The params below are required 
     width = 51,height = 51,numFrames = 2,-- The params below are optional; used for dynamic resolution support 
     sheetContentWidth = 102, -- width of original 1x size of entire sheet 
     sheetContentHeight = 51 -- height of original 1x size of entire sheet 
    } 
    local optionQuitSheet = 
    { 
     -- The params below are required 
     width = 51,height = 51,numFrames = 2,-- The params below are optional; used for dynamic resolution support 
     sheetContentWidth = 102, -- width of original 1x size of entire sheet 
     sheetContentHeight = 51 -- height of original 1x size of entire sheet 
    } 

    isFirstTime=true 
    --pauseScreen() 
    dialog=true 

    alertBox = display.newImage("image/popup_dialog.png") 
    alertBox.x = halfW; alertBox.y = halfH 
    alertBox:setReferencePoint(display.CenterReferencePoint) 

    --creating the restart button fot the popup dialog 
    restartBtn = widget.newButton{ 
     defaultFile="image/replay_btn.png",overFile = "image/replay_btn_hover.png", 
     isEnable=true,onRelease = onReplayBtnGameOverRelease -- event listener function 
    } 
    restartBtn.x = halfW 
    restartBtn.y = btnInitailY 

    --creating the level button 
    levelBtn = widget.newButton{ 
     defaultFile="image/menu.png",overFile = "image/menu_hover.png", 
     isEnable=true, onRelease = onLevelBtnGameOverRelease -- event listener function 
    } 
    levelBtn.x = halfW 
    levelBtn.y = restartBtn.y + restartBtn.height + btnMargin 

    --creating the sound on off switch 
    imageSheetSoundOnOff = graphics.newImageSheet("image/sound.png", optionSoundSheet) 
    soundOnOffSwitch = widget.newSwitch 
    { 
     left = screenW * 0.18,top = screenH * 0.73, style = "checkbox", sheet = imageSheetSoundOnOff, 
     initialSwitchState = soundOn,frameOff = "2",frameOn = "1",onRelease = onSoundButtonClicked, onPress = onSoundButtonClicked, 
    } 


    --creating the quit on off switch 
    imageSheetQuitOnOff = graphics.newImageSheet("image/vibration.png", optionQuitSheet) 

    quitOnOffSwitch = widget.newSwitch 
    { 
     left = screenW * 0.7,top = screenH * 0.735,style = "checkbox",sheet = imageSheetQuitOnOff,onPress = onViberationButtonClicked, 
     initialSwitchState = vibrationOn,frameOff = "2",frameOn = "1", 
    } 
    --soundOnOffSwitch:setState({ isOn = soundOn }) 
    --quitOnOffSwitch:setState({ isOn = vibrationOn}) 

    --create/position logo/title image on upper-half of the screen 
    local titleLogo = display.newImageRect("image/gameover.png",144,30) 
    titleLogo:setReferencePoint(display.CenterReferencePoint) 
    titleLogo.x = halfW 
    titleLogo.y = btnInitailY - 65 

    if popupGameOverGroup == nil then 
     popupGameOverGroup = display.newGroup() 
    end 
    -- inserting the buttons and the alert dialog to the popup group 
    popupGameOverGroup:insert(alertBox) 
    popupGameOverGroup:insert(restartBtn) 
    popupGameOverGroup:insert(levelBtn) 
    popupGameOverGroup:insert(soundOnOffSwitch) 
    popupGameOverGroup:insert(quitOnOffSwitch) 
    popupGameOverGroup:insert(titleLogo) 

    transition.from(popupGameOverGroup, {time =1000,x=startTX,y=titleLogo.y,xScale = 1, yScale = 1, 
     transition = easing.inOutExpo}) 

    localGroup:insert(popupGameOverGroup) 

    showAdd() 
end 
関連する問題