How to get parent camera of an object if defined? I tried but could not find any reference about it.
What I am trying to do is, I am using multiple camera and viewport for different thing. Now I have 3 viewport and Camera, actually I need 3 camera but as 3 camera needs 3 viewport I created 3 viewport with 3 camera. One for GUI, one for game and another for Backgroud, background would be scrollable.
Comments
There's only one accessor for getting an object's parent, you'll then need to try to "cast" it into what you expect to see if it's valid or not.
The code
will return the parent camera of an object if it has one and orxNULL otherwise (ie. if it has no parent or if the parent isn't a camera).
As a side note, more than one viewport can use the same camera but the opposite isn't true (many cameras can't be linked to the same viewport).
Out of curiosity, for which purpose do you "need" 3 cameras? Are you doing some compositing?
One camera for GUI, as in my game the player would go from left to right, that camera would be responsible for rendering GUI elements.
Second, for gamneplay element player and other interactive element, this camera would also be fixed
Third, background, other scrollable element like sky, far objects would be drawn here, as I saw in the scrolling demo, I need to move a camera to make scrolling effect.
I think, there might be other easy way to do this, also I am not sure about performance hit of '3 camera' for mobile device, I would love to hear other solution.
Another thing, I am having some difficulty adding multiple viewport with scroll, I think it binds all object with MainViewport , but I need to go more deeper.
I'm using the main camera for GUI as well in my games, simply setting the GUI objects as child of the camera so that their positions remain fixed on screen.
That being said, it doesn't hurt having extra cameras for that, I was just curious.
There won't be any performance hit as long as you don't render objects to more than one camera. Using object groups you can make sure groups are only rendered by a single camera.
As for multiple viewports, I'd need more details as I'm using multiple viewports with Scroll myself and didn't get any trouble. The only thing to keep in mind is that the MainViewport is created by Scroll whereas the other ones will be created directly by you.
If I create my own camera, when should I create it, also if I set ParentCamera to 'MyCustomCamera' for Scroll objects in config, I see the object on both main camera of scroll and 'MyCustomCamera', looks like I first have to unlink any camera then set Parent of that object to 'MyCustomCamera' from code.
Lastly, is it necessary to move a camera to have differential scrolling effect, then I need two camera, one for GUI and game objects, and another for Background with scrolling.
You should never create a camera directly. They'll get created by your viewports.
Parenting isn't linked to rendering. If the object is in the frustum of both cameras, it'll get rendered by both of them. Object groups can be used to make sure objects only get rendered by the appropriate camera. Or old-style Z trick (by playing on the camera depth, which isn't useful anymore, given object groups).
Nope, camera can stay still. The effect is bound to objects. In scroll the toggle will modify all objects, you can can cherry pick which ones you want with differential scrolling by calling orx functions directly.
Now I realize why it was rendered twice, So, ignore my first question, I had an impression that, objects were linked with both viewports, hence rendered twice. I will definitely use object group, for this purpose.
but in scroll tutorial I have found So, I guess if all scrolling objects sets a default object as parent, then moving that parent object would have the same effect. So, I am not moving the camera instead moving the objects, but have the same effect ?
And thank you for your answers, it was much helpful.
It shouldn't matter.
I see.
Yes, Scroll doesn't allow you to fine-tune differential scrolling, but you can still do it via orx itself. Moving the camera or the object doesn't matter, it's the resulting relative position that will be used for simulating differential, inside the render plugin.
My pleasure, glad if it can help you. Don't hesitate if you have any other questions.
Cheers!