Static unmoving background image
by Konrad Carstein · in Torque Game Builder · 06/25/2008 (8:56 pm) · 16 replies
In building a platformer style game, I'd like to have a single background image that is fixed. I've created a long horizontal tilemap for the level, but of course, as the player moves along it, they reach the edge of the background image.
Do I need to actually move the background image along with the horizontal movement of the player, giving the illusion that it isn't moving? Or is there another way?
Thanks
Do I need to actually move the background image along with the horizontal movement of the player, giving the illusion that it isn't moving? Or is there another way?
Thanks
#2
The problem you are going to have is the camera will move with the player in all directions. If your level is also tall, you'll need to repeat the process for the y axis both top and bottom.
Most of the work will be done in the onUpdate function of the player.
06/26/2008 (4:04 am)
If you're making a board that the player walks through then you want to mount the camera to the player. This will make the player look like they are walking in the level. At a certain point (some where on the x axis on both sides of the map) you want to unmount the camera, so that the player walks to the edge of the tile map with out showing the end of the background image map. The problem you are going to have is the camera will move with the player in all directions. If your level is also tall, you'll need to repeat the process for the y axis both top and bottom.
Most of the work will be done in the onUpdate function of the player.
#3
06/26/2008 (2:20 pm)
Definately go with a GuiBitmapCtrl or even a second SceneWindow in mainscreen.gui. I use it so that I can crossfade backgrounds between screens. If you use a SceneWindow then you can do things like slowly scrolling clouds or a parallax effect.
#4
Thanks for the wonderful advice.
Just another quick question in case any of you come back to review this thread. Is there any way to see GUI controls in the level editor? LIke if I were to add a "score" text that I also need to be stationary as the player moves along, would I be able to see that GUI when working on the level?
Thanks!
06/26/2008 (7:12 pm)
The GuiBitmapCtrl seemed to work perfectly for what I had envisioned. I'm still very unfamiliar with the GUI as it applies to TGB, but have a few items on my "to do" list that I'm sure will start me digging deeper on the topic.Thanks for the wonderful advice.
Just another quick question in case any of you come back to review this thread. Is there any way to see GUI controls in the level editor? LIke if I were to add a "score" text that I also need to be stationary as the player moves along, would I be able to see that GUI when working on the level?
Thanks!
#5
Well you could try dynamically adding some or your controls to the level editor's gui. In more detail what I mean is something like "LevelEditorGui.add(YourGui);" Its not actually called levelEditorGui by the way, and tracking down exactly where it would need to be added would involve some dissection of the level editor scripts.
The console still works in the level editor, but unfortunately something simple like "Canvas.setContent(yourGui)" or "Canvas.pushDialog(yourGui)" would not work, because then your gui would completely replace the level editor.
06/26/2008 (9:42 pm)
Nope. The level editor isn't using any of your guis, it has its own. Well you could try dynamically adding some or your controls to the level editor's gui. In more detail what I mean is something like "LevelEditorGui.add(YourGui);" Its not actually called levelEditorGui by the way, and tracking down exactly where it would need to be added would involve some dissection of the level editor scripts.
The console still works in the level editor, but unfortunately something simple like "Canvas.setContent(yourGui)" or "Canvas.pushDialog(yourGui)" would not work, because then your gui would completely replace the level editor.
#6
06/27/2008 (5:54 pm)
I use multiple scene windows because it lets me treat the background just like any other scene. I can have a background image and text and animations and what-not. I find it a little more flexible than guis in-game.
#7
it works pretty well:
http://tdn.garagegames.com/wiki/TGB/Behaviors/Parallax_Object
06/29/2008 (3:02 pm)
Um you should use the parallax behavior to do this.. easy to use. set x=0 and y=100.. you can adjust your x value to parralax a little bit to give it depth.. say 10 which is a nice effect for a shallow back-wall. it works pretty well:
http://tdn.garagegames.com/wiki/TGB/Behaviors/Parallax_Object
#8
06/29/2008 (8:37 pm)
Nikos I've been looking into using multiple scene windows for that same reason, the one question I have is can you use the editor to modify the other scene windows or do I have to do it through scripting?
#9
tdn.garagegames.com/wiki/TGB/PlatformerStarterKit/Parallax_Layers
I developed it for the PSK but it is easy enough to use in any project.
Shane, it depends on how you set up the Canvas and manage multiple scene windows. In the above url I load in level files which are edited by the level editor yourself. You could, however, control the whole thing via script with a few mods here or there, but I find the editor easier.
06/29/2008 (8:42 pm)
If you're going down the path of multiple scene windows you should also check out this method:tdn.garagegames.com/wiki/TGB/PlatformerStarterKit/Parallax_Layers
I developed it for the PSK but it is easy enough to use in any project.
Shane, it depends on how you set up the Canvas and manage multiple scene windows. In the above url I load in level files which are edited by the level editor yourself. You could, however, control the whole thing via script with a few mods here or there, but I find the editor easier.
#10
06/30/2008 (9:14 pm)
Yeah I was hoping to use the editor, since as you said its alot easier. Thank you very much for the help.
#11
Does anybody have some info on implementing that concept or the layers themselves in just a vanilla implementation, "out of the box"?
Thanks much!
07/01/2008 (10:36 pm)
I don't want to sound like a slacker, but I also really like the idea of the Parallax layers. However I do not have the PlatformerStarterKit so I don't seem to have a GameMethods.cs file.Does anybody have some info on implementing that concept or the layers themselves in just a vanilla implementation, "out of the box"?
Thanks much!
#12
Copy the scripts from the TDN page into a new file, name it whatever you like but I will call it "ParallaxMethods.cs". Save this file into your game/gameScripts folder and execute it in the usual place you execute your scripts in game.
Replace any camera mount/dismount calls with the two new mounting functions that were downloaded. These ensure that the cameras are mounted/dismounted for each of the parallax windows you have used.
To load a parallax level you can use two methods, load them directly via script (not so good for multiple levels) or let your scenegraph do it upon loading. I have put a more detailed explanation of the parameters in the loading functions in the TDN page.
Basically, you have to select a type of layer (foreground or background), the level file (just a regular .t2d level created in the editor) and the zoom level for that layer (use less than 1 for background and greater than 1 for foreground).
I hope that made sense. If you need any further help, feel free to ask!
07/01/2008 (10:55 pm)
Alrighty!Copy the scripts from the TDN page into a new file, name it whatever you like but I will call it "ParallaxMethods.cs". Save this file into your game/gameScripts folder and execute it in the usual place you execute your scripts in game.
Replace any camera mount/dismount calls with the two new mounting functions that were downloaded. These ensure that the cameras are mounted/dismounted for each of the parallax windows you have used.
To load a parallax level you can use two methods, load them directly via script (not so good for multiple levels) or let your scenegraph do it upon loading. I have put a more detailed explanation of the parameters in the loading functions in the TDN page.
Basically, you have to select a type of layer (foreground or background), the level file (just a regular .t2d level created in the editor) and the zoom level for that layer (use less than 1 for background and greater than 1 for foreground).
I hope that made sense. If you need any further help, feel free to ask!
#13
1. I'm using the dynamic fields of the level and then initializing the layers. Where is the best place to do that?
I currently am calling it from my game.cs like so:
This seems to work fine, but wanted to make sure it was being done in an appropriate spot.
2. I get the below error when my level loads. It hasn't seemed to cause any problems, but I do not quite understand it, or know which object it is talking about.
And if it makes any difference i'm integrating this with the platformer camera behavior. So the attach and detach methods were put into the behavior's method as such:
But otherwise it works great! I'm excited. The overall feel on the forums is that the GUI builder is often cumbersome for basic UI stuff and this might be a great alternative, to build the UI as a level.
07/01/2008 (11:33 pm)
Excellent! Thank you. This was very helpful. Couple more questions though if I may.1. I'm using the dynamic fields of the level and then initializing the layers. Where is the best place to do that?
I currently am calling it from my game.cs like so:
sceneWindow2D.loadLevel(%level); initialiseParallaxLayers();
This seems to work fine, but wanted to make sure it was being done in an appropriate spot.
2. I get the below error when my level loads. It hasn't seemed to cause any problems, but I do not quite understand it, or know which object it is talking about.
t2dSceneObject::mount() - Couldn't find/Invalid object '1345'.
And if it makes any difference i'm integrating this with the platformer camera behavior. So the attach and detach methods were put into the behavior's method as such:
function PlatformerCameraBehavior::attachCamera(%this)
{
if (sceneWindow2D.getIsCameraMounted())
detachCamera();
// mount the camera to the scene object and start the onUpdate function
sceneWindow2D.mount(%this.owner, "0 0", %this.trackForce, true);
%this.owner.enableUpdateCallback();
// Mount parallax mounts
if (isObject(ParallaxLayerMounts))
{
for (%i = 0; %i < ParallaxLayerMounts.getCount(); %i++)
ParallaxLayerMounts.getObject(%i).mount(%this);
}
}
function PlatformerCameraBehavior::detachCamera(%this)
{
if (!sceneWindow2D.getIsCameraMounted())
return;
sceneWindow2D.dismount();
%this.owner.disableUpdateCallback();
// Dismount parallax mounts
if (isObject(ParallaxLayerMounts))
{
for (%i = 0; %i < ParallaxLayerMounts.getCount(); %i++)
ParallaxLayerMounts.getObject(%i).dismount();
}
}But otherwise it works great! I'm excited. The overall feel on the forums is that the GUI builder is often cumbersome for basic UI stuff and this might be a great alternative, to build the UI as a level.
#14
2. Change:
07/02/2008 (12:03 am)
1. You'll need to initialise parallax layers anywhere that you load a level (you could even place it at the bottom of the loadLevel function found in your common directory). However, a small oversight is that I haven't cleared existing ParallaxBackGround/ForeGrounds inside the initialisation function (I have now updated the TDN page to reflect the full change):for (%i = 0; isObject("ParallaxBackground" @ %i); %i++)
("ParallaxBackground" @ %i).delete();
for (%i = 0; isObject("ParallaxForeground" @ %i); %i++)
("ParallaxForeground" @ %i).delete();2. Change:
// From ParallaxLayerMounts.getObject(%i).mount(%this); // To ParallaxLayerMounts.getObject(%i).mount(%this.owner);
#15
07/02/2008 (8:35 pm)
Going with multiple scene windows, you load up each individual scene into the editor. I work on the foreground which is one level (scene graph), then load the background which is a separate level (scene graph). It's all done in the editor. The only thing you can't do is see them at the same time. That's only visible when the game is run. The only thing you need to do in script is "loadLevel(...)" for each scene window just like you would if there was only one scene window.
#16
This clears up that strange error, but at the sametime causes my FG layer to act very strangely. I think because the %this.owner is the player in this case so something gets wierd with the camera mount. I'll have to poke around.
Odly enough though if I totally remove the additions to mounting the camera:
It still seems to work fine.
07/02/2008 (8:49 pm)
Quote:
// From
ParallaxLayerMounts.getObject(%i).mount(%this);
// To
ParallaxLayerMounts.getObject(%i).mount(%this.owner);
This clears up that strange error, but at the sametime causes my FG layer to act very strangely. I think because the %this.owner is the player in this case so something gets wierd with the camera mount. I'll have to poke around.
Odly enough though if I totally remove the additions to mounting the camera:
// Mount parallax mounts
if (isObject(ParallaxLayerMounts))
{
for (%i = 0; %i < ParallaxLayerMounts.getCount(); %i++)
ParallaxLayerMounts.getObject(%i).mount(%this);
}It still seems to work fine.
Associate Phillip O'Shea
Violent Tulip