How to make one display group remain fixed in every scene in the Crown?

I have a group displaying the level and state, and I want this group to remain in the same place when the scene changes. How can i achieve this? I use the director class to change the scene.

+1
source share
1 answer

Do you want the object / group displayed in each scene.? Then you can do the following:

- 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

Save encoding ................ ๐Ÿ˜ƒ

+3
source

Source: https://habr.com/ru/post/1528928/


All Articles