Hi all,
I am having difficulty assigning a particular object to several behavioral groups.
My first example:
I am creating an app with multiple scenes (using storyboard) and with a moving camera in one of the scenes. It is a rule that an object cannot be assigned to more than one group. Therefore, I am using an unorthodox way to assign a display object to the scene.view group for my scene as well as to move only certain objects in that scene with the movecamera function.
- Defining objects Coding (not all - main points only):
local storyboard = require(“storyboard”)
local scene = storyboard.newScene()
function scene:createScene(event)
local screenGroup = self.view
local sky = display.newImage(“sky.png”)
screenGroup:insert(sky)
local tree = display.newImage(“tree.png”)
screenGroup:insert(tree)
local man = display.newImage(“man.png”)
screenGroup:insert(man)
local forward_button = display.newImage(“button.png”)
screenGroup:insert(forward_button)
end
…
- Lets say if i have a movecamera function that follows the man forward, when I press the forward button.
local background = display.newgroup()
background : insert (sky)
background : insert (tree)
local function moveCamera()
if (man.x > 10) then
background.x = -man.x+10
end
end
- I cannot assign the sky and tree objects to both the scene.view and background groups. At the same time, I want the forward_button to stay where it is, so I need to call the sky and tree separately.
I could do this:
local function moveCamera()
if (man.x > 10) then // 10 is the initial x distance of man
scene.view[1].x = (original sky’s position) - man.x +10
scene.view[2].x = (original tree’s position) - man.x +10
end
end
This works fine assuming the number of objects are small, and no objects in the middle are destroyed in the game.
Is there a way I can create or define a separate sub-group or behavioral category that I can control certain objects within the scene.view group without relying on index?
Thank you! Any help will be greatly appreciated!
Jon