2013-04-15 60 views
0

我正在使用導演,從一個場景移到另一個場景。我有一個問題,即移動到任何場景時,來自Intor的按鈕和文本字段仍然位於屏幕的頂部。corona sdk - scene keep old items

如何在移動到下一個場景之前刪除項目(文本字段,來自intro.lua屏幕的btns)?

enter code here  
-- into.lua 
module(..., package.seeall) 
function new() 
-- 
-- Project: NativeKeyboard2 
-- 

local widget = require("widget") 

require("hijacks") 

local tHeight  -- forward reference 

------------------------------------------- 
-- General event handler for fields 
------------------------------------------- 

-- You could also assign different handlers for each textfield 

local function fieldHandler(textField) 
    return function(event) 
     if ("began" == event.phase) then 
      -- This is the "keyboard has appeared" event 
      -- In some cases you may want to adjust the interface when the keyboard appears. 

     elseif ("ended" == event.phase) then 
      -- This event is called when the user stops editing a field: for example, when they touch a different field 

     elseif ("editing" == event.phase) then 

     elseif ("submitted" == event.phase) then 
      -- This event occurs when the user presses the "return" key (if available) on the onscreen keyboard 
      print(textField().text) 

      -- Hide keyboard 
      native.setKeyboardFocus(nil) 
     end 
    end 
end 

-- Predefine local objects for use later 
local nameField, phoneField 
local fields = display.newGroup() 



------------------------------------------- 
-- *** Create native input textfields *** 
------------------------------------------- 

-- Note: currently this feature works in device builds or Xcode simulator builds only (also works on Corona Mac Simulator) 
local isAndroid = "Android" == system.getInfo("platformName") 
local inputFontSize = 18 
local inputFontHeight = 30 
tHeight = 30 

if isAndroid then 
    -- Android text fields have more chrome. It's either make them bigger, or make the font smaller. 
    -- We'll do both 
    inputFontSize = 14 
    inputFontHeight = 42 
    tHeight = 40 
end 

nameField = native.newTextField(40, 120, 200, tHeight) 
nameField.font = native.newFont(native.systemFontBold, inputFontSize) 
nameField:addEventListener("userInput", fieldHandler(function() return nameField end)) 

phoneField = native.newTextField(40, 160, 200, tHeight) 
phoneField.font = native.newFont(native.systemFontBold, inputFontSize) 
phoneField.inputType = "phone" 
phoneField:addEventListener("userInput", fieldHandler(function() return phoneField end)) 


-- Add fields to our new group 
fields:insert(nameField) 
fields:insert(phoneField) 

------------------------------------------- 
-- *** Add field labels *** 
------------------------------------------- 

local defaultLabel = display.newText("الاسم", 250, 120, native.systemFont, 18) 
defaultLabel:setTextColor(255, 0, 0) 

local defaultLabel = display.newText("رقم الجوال", 250, 160, native.systemFont, 18) 
defaultLabel:setTextColor(255, 0, 0) 

-- ------------------------------------------- 
-- -- Create a Background touch event 
-- ------------------------------------------- 


local listener = function(event) 
    -- Hide keyboard 
    print("tap pressed") 
    native.setKeyboardFocus(nil) 

    return true 
end 

-- Determine if running on Corona Simulator 
-- 
local isSimulator = "simulator" == system.getInfo("environment") 
if system.getInfo("platformName") == "Mac OS X" then isSimulator = false; end 

-- Native Text Fields not supported on Simulator 
-- 
if isSimulator then 
msg = display.newText("الرجاء ادخال اسمك ورقم جوالك", 0, 280, native.systemFontBold, 12) 
msg.x = display.contentWidth/2  -- center title 
msg:setTextColor(255,0,0) 
end 

-- -- Add listener to background for user "tap" 
-- bkgd:addEventListener("tap", listener) 
-- display.remove(obj) 
-- obj = nil  

local introGroup = display.newGroup(); 

    local background = display.newImage("graphics/intro_background.png")   
    local begin = display.newImage("graphics/begin_button.png") 
    begin.x = 160; 
    begin.y = 400; 
    begin.scene = "menu"; 

    introGroup:insert(background); 
    introGroup:insert(begin); 

    begin:addEventListener("touch", changeScene) 

return introGroup; 

end 

回答

1

日冕提供了一個非常好的特點,那就是「故事板」。我是給你一個簡要說明,試試這個 -

  • 故事板 - 這是一個場景(例如,「屏幕」或「視圖「)管理庫,爲開發人員提供了一種在Corona SDK應用程序中創建場景模塊並進行轉換的簡單方法。

    語法 - 本地故事板=需要 「故事板」

    實施例 -
    本地SCENE1 = storyboard.newScene( 「名場景的」)

    下面是在故事板中使用的不同的事件 -

    1 - 創建場景 -
    - 被叫時的情景的視圖不存在:

    功能場景:createScene(事件) 本地組= self.view 端

    2-進入場景 - - 場景後,立即調用已經移動屏幕上:

    功能場景:enterScene(事件) 本地組= self.view 端

    3-退出場景 - - 當場景即將移動offscree調用N:

    功能場景:exitScene(事件) 本地組= self.view

    4 - 銷燬場景 - - 被叫之前去除的場景的 「視圖」(顯示組)

    功能場景:destroyScene(事件) 本地組= self.view 端

它會幫助你。

+0

感謝您的回覆 – malbar