How to make one display group stay fixed in every scene in Corona?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 17:01:08

问题


I have a level and status bar display group and I want this group stay at the same place when the scene changes. How can I achieve this? I am using director class for scene changes.


回答1:


Do you want an object/group appear in every scene..? Then you can do as follows:

-- main.lua --

 local director=require("director")
 local maingroup=display.newGroup()
 maingroup:insert(director.directorView)
 director:changeScene("menu")
 return maingroup

-- status.lua --

 local function myObject(group,x,y,imagePath)

   local image = display.newImage( imagePath )
   image.x, image.y = x, y
   group:insert( image )

   -- add motion (if needed) --
   transition.to(image, {time=1000, x=160, y=300, transition=easing.inOutQuad})

   -- add Listener --
   image:addEventListener("touch", function() print("imageClicked") end )
end

local status = { myObject = myObject }

return status

-- menu.lua -- (This is your game scene)

module(...,package.seeall)

function new()

    -- require object page --
    local status = require "status"

    -- create a display group --
    local localGroup = display.newGroup()

    -- call object --
    status.myObject(localGroup, 200, 100, "Icon-xhdpi.png")

 return localGroup
end

Keep Coding................ 😃



来源:https://stackoverflow.com/questions/18205978/how-to-make-one-display-group-stay-fixed-in-every-scene-in-corona

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!