Help W/ background relative to camera
by Jordan Hirsh · in Torque Game Builder · 03/02/2007 (7:38 pm) · 5 replies
I am making a side scrolling platform style game and wish to keep several background images/scrollers in a position relative to the camera. I also must be able to put these images behind tile layers etc...
I have tried a couple of different ways of doing this and have searched the forums and found a few mentions of using a sceneObjects to keep a hud relative to the camera but cannot seem to find any information on how they can be used.
The first solution I tried was to mount the images to the player and mount the camera to the player, however when the cameras force isn't 100% the player can force the camera to outrun the images mounted to the player.
Another solution could be to poll the camera postion using getCurrentCameraPosition() however this would add a seemingly large amount of overhead. If anyone has any suggestions on additional methods of implementation I would greatly appreciate it.
thank you for your time,
Jordan Hirsh
I have tried a couple of different ways of doing this and have searched the forums and found a few mentions of using a sceneObjects to keep a hud relative to the camera but cannot seem to find any information on how they can be used.
The first solution I tried was to mount the images to the player and mount the camera to the player, however when the cameras force isn't 100% the player can force the camera to outrun the images mounted to the player.
Another solution could be to poll the camera postion using getCurrentCameraPosition() however this would add a seemingly large amount of overhead. If anyone has any suggestions on additional methods of implementation I would greatly appreciate it.
thank you for your time,
Jordan Hirsh
#2
I have not tried my second solution, I was sure there had to be a more elegant implementation. For some reason I completely spaced out the force when mounting the images. I think mounting with the same force will solve my problems.
03/03/2007 (9:25 am)
Thank you for the response Ben. The reason I called the background images a HUD was mainly because I want them to act in the same way a HUD does (except in the background) I am sorry if I was unclear.I have not tried my second solution, I was sure there had to be a more elegant implementation. For some reason I completely spaced out the force when mounting the images. I think mounting with the same force will solve my problems.
#3
03/03/2007 (1:52 pm)
Awesome! Good luck!
#4
I continue to have problems finding a good solution to this problem. Let me explain in more detail what I am trying to do. I am making a side scrolling platformer; the majority of levels are outside. A main theme of this game is the moon; as such, the moon should always be in the background. The moon should not jump with the player, but when the camera moves on the y axis so should the moon. The moon should not chase the player around but when the camera moves on the x axis so should the moon.
Solution #1 mount to the player with the same force as the camera: problem when camera hits world limits and player moves toward world limit the moon continues to move with player. This problem is exacerbated when the player jumps.
Solution #2 getCurrentCameraPosition: seems to return the current center of the camera which reproduces problem above.
Solution #3 sceneWindow2D.getPosition(): when called returns (0 0)
Solution #4 use sceneWindow2D.getPositionX(): works great! but when I try sceneWindow2D.getPositionY() I am given the error... "Unknown command getPositionY."
I feel like I am about out of options here. Has anyone else attempted to move background images relative to the camera position?
03/05/2007 (5:51 pm)
Looks like I do need further assistance... I continue to have problems finding a good solution to this problem. Let me explain in more detail what I am trying to do. I am making a side scrolling platformer; the majority of levels are outside. A main theme of this game is the moon; as such, the moon should always be in the background. The moon should not jump with the player, but when the camera moves on the y axis so should the moon. The moon should not chase the player around but when the camera moves on the x axis so should the moon.
Solution #1 mount to the player with the same force as the camera: problem when camera hits world limits and player moves toward world limit the moon continues to move with player. This problem is exacerbated when the player jumps.
Solution #2 getCurrentCameraPosition: seems to return the current center of the camera which reproduces problem above.
Solution #3 sceneWindow2D.getPosition(): when called returns (0 0)
Solution #4 use sceneWindow2D.getPositionX(): works great! but when I try sceneWindow2D.getPositionY() I am given the error... "Unknown command getPositionY."
I feel like I am about out of options here. Has anyone else attempted to move background images relative to the camera position?
#5
You can mount your moon to the camera object. This isn't relative actually.
Ok, for relative moving you can use the coordinates of the camera object and move your moon or what else to the relative position in every frame. This is inefficient a little but you can make new console object in the source (if you have pro license). The con is what you won't be able to use moveTo or rotateTo commands or any speed function for it.
03/06/2007 (8:20 am)
As usual the camera is represents a dummy t2dSceneObject with mounted sceneWindow2D to it.You can mount your moon to the camera object. This isn't relative actually.
Ok, for relative moving you can use the coordinates of the camera object and move your moon or what else to the relative position in every frame. This is inefficient a little but you can make new console object in the source (if you have pro license). The con is what you won't be able to use moveTo or rotateTo commands or any speed function for it.
Torque Owner Ben R Vesco
2. Why not mount the images with the same force as the camera? Then they will all lag at the same rate.
3. Are you sure the overhead of your other solution is too large? Don't optimize yourself out of an idea before you even know it causes real world performance problems.
4. Have you tried the platformer and side scroller tutorials? They both use scrolling backgrounds. Maybe there is something there you can use?