Game Development Community

BUG: Mounting to camera with offset

by Matias Kiviniemi · in Torque X 2D · 03/18/2007 (6:32 am) · 6 replies

Hi,

It seems that mounting an object ot the T2DSceneCamera using a mount offset has no effect. I.e. using

obj.Mount(camera, "LinkPointName", mountOffset, 0.0f, true);

result in obj to be mounted in the middle of camera (using 'null' as linkpoint has the same result). What I'd like to achieve is mounting GUI/HUD-objects to a static place of the screen, e.g. corner of the screen.

Matias

#1
03/18/2007 (8:19 am)
I honestly don't think that was an expected implemention choice, but I do see your thought process for sure.

I've not yet taken a look deeply myself at doing HUD style elements, but you may want to take a look at the SplitScreen starter kit, specifically game.cs, which has some interesting functionality in the BeginRun:

// create our main display control
            _playScreen = _SetupPlayScreen();

            // create two side-by-side GUISceneViews
            _leftView = _AddSceneView(_playScreen, new Vector2(0, 0), new Vector2(512, 768));
            _rightView = _AddSceneView(_playScreen, new Vector2(512, 0), new Vector2(512, 768));

            _leftView.Name = "leftView";
            _rightView.Name = "rightView";

            // create and attach a camera for each view
            _leftCam = _CreateAndAttachCameraToView(_leftView, new Vector2(0, 0), new Vector2(50, 75));
            _rightCam = _CreateAndAttachCameraToView(_rightView, new Vector2(50, 0), new Vector2(50, 75));

            _AddOverlay("leftOverlay", _playScreen, new Vector2(0, 0), new Vector2(512, 768), @"data\images\Overlay.png");
            _AddOverlay("rightOverlay", _playScreen, new Vector2(512, 0), new Vector2(512, 768), @"data\images\Overlay.png");

            // mount the cameras to each respective player
            _leftCam.Mount(_player1, String.Empty, true);
            _rightCam.Mount(_player2, String.Empty, true);

            GUICanvas.Instance.SetContentControl(_playScreen);

I realize that one example that's quick and dirty doesn't provide much in the way of learning, so I've sent an email around the office to see if anyone has a more dynamic set of examples, but this may get you started.
#2
03/18/2007 (9:43 am)
I don't know how big the camera is, but if its very small that could be the problem. Remember, you can't place a linkpoint outside of an object, and if you are trying to do that, you might fail. maybe try mounting a huge scene object to the camera, and mount your gui from there?
#3
03/18/2007 (9:43 am)
Thats my novice guess..
#4
03/18/2007 (2:11 pm)
Hmm.. I guess T2DSceneCamera is some kind of special case.. After some more experiments, seems like it doesn't have the Linkpoints-component (meaning the property is always null). Even after accessing the property, setting the .CreateWithLinkPoints to true or mounting something to it, the T2DSceneCamera.LinkPoints is still null. You can still mount things to it, but I guess it ignores the linkpoint-parameter. I'll have to try that mounting to a big "proxy-object" :)

But did I understand correctly the intention of the overloaded .Mount method that has the offset-parameter, or is it for something else?
#5
03/18/2007 (2:28 pm)
As a quick test, if I:
- create a T2dSceneObject proxy with same extent as the camera
- mount the proxy to camera
- mount my object to proxy
then my object disapear entirely. But considering the time of day, the chances of some human error is not too small :)
#6
04/12/2007 (2:14 am)
Hmm.. without actually checking (I'll have to remember to check this out when I get into the office tomorrow), I suspect the problem is that the camera might have a Size of 0 so *any number* in local coordinates would be the center of the camera. You're definitely using the offset parameter properly. The problem with mounting things to the camera is that when the zoom or aspect ratio change, the size property would have to be updated, not to mention the fact that if you zoom the camera would have to know whether or not to scale the objects (if they are supposed to be used as HUD elements, etc.).

The "mount object to object to camera" should work. It definitely shouldn't have hidden your object... unless your proxy object was invisible and you mounted the child object with InheritMountVisibility(or whatever it's called) set to true. *_*

Edit: I'll try to remember to post back tomorrow with more info about this.