TDN Platformer Tutorial
by Adam Larson · in Torque Game Builder · 10/11/2005 (8:49 pm) · 55 replies
For those of you waiting for the 1.02 version of the platformer tutorials, here is an update.
I added 1.02 compatibility to the first article of the platformer tutorial on TDN. The first article was the only real show stopper for use with the current T2D version, so only minor tweaks should be necessary to get the rest of the code working. I'll add the specifics in the coming days.
Also, I am a horrible artist, so if there's anyone out there that wants to help out by providing some art, let me know. Since these tutorials are mainly code based, it's not imperative that I get good art. But, it would give a much better initial impression of the tutorials if they looked good. Specifically, I need a tile set for the sample levels and a character with run, jump, and dieing animations.
Any comments, suggestions, or critiques on the tutorials are welcome and encouraged. My goal is to reach a feature and quality level fit for a starter kit and I can't get there without feedback.
I added 1.02 compatibility to the first article of the platformer tutorial on TDN. The first article was the only real show stopper for use with the current T2D version, so only minor tweaks should be necessary to get the rest of the code working. I'll add the specifics in the coming days.
Also, I am a horrible artist, so if there's anyone out there that wants to help out by providing some art, let me know. Since these tutorials are mainly code based, it's not imperative that I get good art. But, it would give a much better initial impression of the tutorials if they looked good. Specifically, I need a tile set for the sample levels and a character with run, jump, and dieing animations.
Any comments, suggestions, or critiques on the tutorials are welcome and encouraged. My goal is to reach a feature and quality level fit for a starter kit and I can't get there without feedback.
About the author
#22
Yup camera is working now; I did something dumb. I had:
instead of
10/13/2005 (4:53 pm)
@Adam,Yup camera is working now; I did something dumb. I had:
%this.camera = new fxSceneWindow2D() { scenegraph = t2dSceneGraph; };instead of
%this.camera = new fxSceneObject2D() { scenegraph = t2dSceneGraph; };
#23
I found a small bug. If you stand under a platform and jump (so the player's head hits the platform), the player starts to bounce. Looks like a stuck super bouncy ball.
10/13/2005 (4:59 pm)
@Adam,I found a small bug. If you stand under a platform and jump (so the player's head hits the platform), the player starts to bounce. Looks like a stuck super bouncy ball.
#24
10/13/2005 (5:53 pm)
Hmmm, I had that problem a while ago and thought I fixed it. Thanks for the info.
#25
I noticed something else. The platformer tutorial seems to behave differently on different machines. Even differently on the same machine if you choose a different resolution. It appears that:
10/16/2005 (9:58 am)
@Adam,I noticed something else. The platformer tutorial seems to behave differently on different machines. Even differently on the same machine if you choose a different resolution. It appears that:
//-----------------------------------------------------------------------------
// onUpdateScene
// Called by the engine every frame. Again, we just dispatch execution to
// functions that deal with specific objects.
//-----------------------------------------------------------------------------
function fxSceneGraph2D::onUpdateScene(%this)
{
// We only care about our main scene graph. The editors all have scene
// graphs of their own, but we don't want to deal with them.
if (%this != t2dscenegraph.getID())
return;
// Update the player.
updatePlayer();
// Update the camera.
$camera.update();
// Reset the run surface variable. If we actually are on a run surface, the
// onCollision callback will fix this before anything important happens.
$runSurface = -1;
}is called every frame. So this can have an affect on how high the player can jump and how quick the camera moves, etc.
#26
10/16/2005 (10:09 am)
The only thing that is frame rate dependent because of this is the fall delay (which explains your previous problem - thanks). All of the movement is done through setting velocities so the engine will handle consistent timing and movement (except the camera, but that is tracking the player and thus still not a problem). If I were setting the position of objects directly, then this would be an issue.
#27
That makes sense. I was initially setting the player off camera, so when the game started up the camera would move to the player. On my machine you don't even notice it but on a slower machine, that I tried, it was very noticeable (choppy movement). I guess its not a problem, I just need to add a setInitialPosition function on the camera.
I have to say I'm looking forward to the rest of your tutorial as it has helped me out immensely.
10/16/2005 (10:44 am)
@Adam,That makes sense. I was initially setting the player off camera, so when the game started up the camera would move to the player. On my machine you don't even notice it but on a slower machine, that I tried, it was very noticeable (choppy movement). I guess its not a problem, I just need to add a setInitialPosition function on the camera.
I have to say I'm looking forward to the rest of your tutorial as it has helped me out immensely.
#28
Are you sure of that? I've tested with T2D 1.0.2 using only
velocities and gravity for a plataformer demo and the
reach of the jump depends seriously of the hardware underlying,
Melv pointed me that this is going to be fixed in 1.1 though, I hope so.
10/24/2005 (9:45 am)
@Adam:Quote:
All of the movement is done through setting velocities so the engine will handle consistent timing and movement...
Are you sure of that? I've tested with T2D 1.0.2 using only
velocities and gravity for a plataformer demo and the
reach of the jump depends seriously of the hardware underlying,
Melv pointed me that this is going to be fixed in 1.1 though, I hope so.
#29
www.garagegames.com/mg/forums/result.thread.php?qt=35725
10/24/2005 (11:36 am)
I also see the same problems as Adam Johnston when running on different machines. In fact, there's a thread about this type of issue in the collision / physics forum:www.garagegames.com/mg/forums/result.thread.php?qt=35725
#30
On a side note, I haven't updated things in a while because school just started. Actually, school did just start, but the real culprit is Age of Empires III.
10/24/2005 (12:49 pm)
Alright. I wasn't aware of this, but I'm fairly sure it's not supposed to be that way. Since it doesn't seem to be a show stopper, I'm hoping it'll be OK until 1.1 comes out. Thanks for letting me know, though.On a side note, I haven't updated things in a while because school just started. Actually, school did just start, but the real culprit is Age of Empires III.
#31
10/25/2005 (1:37 am)
Should have mentioned that I think this is a great tutorial. Really helped me get a few things straight in my head.
#32
In your examples both the player and platforms's scenegraph is stated as t2dscene but the "out of box" name for the scenegraph is t2dsceneGraph
At least in 1.02 version
10/25/2005 (6:34 am)
TypoIn your examples both the player and platforms's scenegraph is stated as t2dscene but the "out of box" name for the scenegraph is t2dsceneGraph
At least in 1.02 version
#33
10/26/2005 (3:15 pm)
But isn't 't2dScene' just a name? It quite easily be called 'fred' by using:new t2dSceneGraph(fred);
#34
I'm using a basic t2d .exe, I followed the updated camera tutorial, and I corrected the statements for 1.0.2.
These are the errors I get in my output:
T2D/client/game.cs (12): Unable to find object: '' attempting to call function 'getArea'
fxSceneWindow2D::setViewLimitOn() - Invalid number of parameters!
fxSceneObject2D::setWorldLimit - Invalid number of parameters!
So... i've got no idea what to do, any suggestions?
Erm, please?
11/02/2005 (7:04 pm)
Okay, the camera tutorial was just updated and I followed it. To my amazement I actually got the camera working perfectly! Until I ran the game again. For some reason the camera only works right if I delete all the .dso files then run it. I'm using a basic t2d .exe, I followed the updated camera tutorial, and I corrected the statements for 1.0.2.
These are the errors I get in my output:
T2D/client/game.cs (12): Unable to find object: '' attempting to call function 'getArea'
fxSceneWindow2D::setViewLimitOn() - Invalid number of parameters!
fxSceneObject2D::setWorldLimit - Invalid number of parameters!
So... i've got no idea what to do, any suggestions?
Erm, please?
#35
You'll want to change the $camera.setLimits line to something like this:
If that doesn't fix things, give me a more detailed explanation of what isn't working about the camera and I'll see what I can do.
I'll try to write something tomorrow detailing all the updates and 1.02 compatibility.
11/02/2005 (7:47 pm)
The second two errors are only there because of the first error. The first error is basically saying that the object you're calling getArea on doesn't exist. Also, getArea only exists in T2D 1.1. My version of the createLevel function looks like this:function createLevel()
{
$gravity = 700;
$spawnPoint = "-20 -30";
%tileMap = new fxTileMap2D() { scenegraph = t2dscenegraph; };
%tileMap.loadTileMap("./maps/platformer.tile");
%layer = %tileMap.getTileLayer(0);
%layer.setCollisionActive(false, true);
%layer.setGroup($platformGroup);
%layer.setLayer($platformLayer);
%layer.setPosition("0 0");
$camera.setLimits(%layer.getArea());
resetPlayer($spawnPoint);
}You'll want to change the $camera.setLimits line to something like this:
%halfWidth = %layer.getWidth() / 2; %halfHeight = %layer.getHeight() / 2; %x = %layer.getPositionX(); %y = %layer.getPositionY(); %area = (%x - %halfWidth) SPC (%y - %halfHeight) SPC (%x + %halfWidth) SPC (%y + %halfHeight); $camera.setLimits(%area);
If that doesn't fix things, give me a more detailed explanation of what isn't working about the camera and I'll see what I can do.
I'll try to write something tomorrow detailing all the updates and 1.02 compatibility.
#36
If I run it with no .dso files it goes perfectly. However if I run it again after the .dso files have been compiled only the T2D splash screen shows up. Not exactly sure what's going on with that.
11/02/2005 (7:59 pm)
Thanks for the quick reply. The additional code there does clear up the error message, however I still have the same problem.If I run it with no .dso files it goes perfectly. However if I run it again after the .dso files have been compiled only the T2D splash screen shows up. Not exactly sure what's going on with that.
#37
11/03/2005 (7:48 am)
Ah yes. I had this problem when I was trying to backport everything to 1.02 a while ago. Very annoying to track down. Basically, the camera's position and area aren't initialized right when it's created so the call to setLimits screws things up. Typeecho($camera.camera.getCurrentCameraArea());in the console and you'll see some funny values. To fix it, change
createCamera(); createLevel();in the setupT2DScene function of client.cs to
schedule(0, 0, createCamera); schedule(0, 1, createLevel);And by the way, this is a 1.02 problem only so when 1.1 comes out, you can ignore this.
#38
As far as I can see, in v1.0.2, the current cameras position is updated as soon as the window is added to the simulation so the "getCurrentCameraArea()" call should work right off the bat.
May you guys are talking about something else and I should read the thread a little more? ;)
- Melv.
11/03/2005 (11:09 am)
Did I fix something here then? I don't see anything in the subversion logs.As far as I can see, in v1.0.2, the current cameras position is updated as soon as the window is added to the simulation so the "getCurrentCameraArea()" call should work right off the bat.
May you guys are talking about something else and I should read the thread a little more? ;)
- Melv.
#39
I actually didn't really look into this much as once I found a fix I sort of ignored it. Because the problem didn't exist in debug builds, I made the above assumption. I just checked the scenewindow code and nothing relevant seems to have changed so maybe the problem does still exist. I'll track it down for you and let you know.
11/03/2005 (11:41 am)
Hey Melv,I actually didn't really look into this much as once I found a fix I sort of ignored it. Because the problem didn't exist in debug builds, I made the above assumption. I just checked the scenewindow code and nothing relevant seems to have changed so maybe the problem does still exist. I'll track it down for you and let you know.
#40
- Melv.
11/03/2005 (11:47 am)
I'd really appreciate that Adam. Being very close to letting this new release go is an anxious time when you know you've probably let a silly bug through the net from v1.0.2.- Melv.
Torque Owner Adam Larson
Glad to hear it! The camera works, too?
Here is a link to my code for the 1.02 version through the sixth tutorial.