How to make one display group stay fixed in every

2019-07-29 07:47发布

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.

标签: lua corona scene
1条回答
forever°为你锁心
2楼-- · 2019-07-29 08:05

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................

查看更多
登录 后发表回答