Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top