Collections and Proxies in relation to Camera (SOLVED)

Hello Defold team and community. Ive been learning Defold for a little over a week and managed to make a fully playable simple infinite jump platformer which I plan to add to the community. Im a developer on Google play (CGC Creative) and was primarily using Eclipse to program with. My issue is however I have a menu screen and a game screen with are collection and have them loading and running successfully but I have a camera object that follows the player Y movement if he/she is in a certain threshold above the cameras Y position. the problem is that the background is parented to the camera on the game screen and it works fine but the background in the main menu gets shifted down whenever I go back to the main menu. I’m assuming both screens are using the same camera but I tried to move it down and even add another camera without any luck. How could I resolve this?

So the breakdown
What exactly is a collection doing?
Are they camera independent?

1 Like

A collection doesn’t actually exist at runtime. It’s just a container/collection of game objects that can be spawned using a collection factory, loaded using a collection proxy or added to another collection.

The camera component sends view and projection updates to the render script. If you’re using the default render script from builtins you’ll see in the on_message function something like this:

elseif message_id == hash("set_view_projection") then
    self.view = message.view
end

The set_view_projection message is sent by the camera component every frame and the render script uses this to decide what portion of the game world to render.

I’m not sure why you’re experiencing the problem you describe. I’m guessing that when you switch back to the menu it is rendered around 0,0 and if you had been playing and shifted the camera vertically the render script will still have the view settings from when the user played the game. What if you move the camera back to 0,0? Or what if you have two cameras, one that is active while playing and one that is centred around 0,0 and used when showing the menu (remember acquire/release camera focus messages)?

Thanks for the reply. I did try both options, setting the camera back at 0,0 after the player dies but I placed it in the camera script’s final function, which is a function I don’t fully understand. Based on tutorials on the site, I’m assuming that the final function gets called right before the corresponding object is removed. Now I think about it, I don’t actually remove the camera when the player dies. The second option, I did try having 2 separate cameras but I don’t remember calling “acquire_camera _focus” on the menu camera. I’m currently away from my workstation so I’ll take a look as soon as I’m able and post an update. I was so accustomed to OOP for over 4 years I was treating collections as individual screens.

Correct.

But you know when the player dies right? Can’t you do go.set_position(vmath.vector3(0,0,0), "url_to_camera") and manually set the camera to 0,0?

A collection can be used as a screen if you use collection proxies and load and unload collections that way. But collections can also be used for many other things.

1 Like

Worked perfectly I just sent a message to tell the camera the player died then set its position to 0,0,0.
But it seems inconvenient/unorganized to be sending messages to the game screen’s camera.

UPDATE, I have 2 cameras working perfectly now by releasing the game cameras focus upon player death, Thanks for the help

1 Like