Game Development Community

3/4 top down perspective

by James Petruzzi · in Torque Game Builder · 03/14/2006 (9:35 pm) · 29 replies

I've been searching the forums, resources, and TDN all night to find information on rendering scenes in a top down perspective like zelda. I've seen a few posts from the summer and before that have given me a general idea of what needs to be done, but i can't seem to put it all together.

From what i gathered, each object on the screen would first have to be put into a SimSet or SimGroup (i have no idea what the difference is) ? My first step was to attempt to find information SimSets. I searched all the documentation given with TGB, TDN, and this site and I can't seem to find anything that actually explains them. if anybody can point me in the direction of reference, it would be greatly appreciated

Next the screen would be scanned and objects lower on the y axis would be rendered..last? i have no idea how that would be done.

i know i can get a kickass game together, but this is quite a huge initial hurdle to get over. anyhow, any information or suggestions would be greatly appreciated at this point. thanks guys!
Page «Previous 1 2
#1
03/14/2006 (9:43 pm)
I've also been researching this for an RPG style game I'd like to create and I was about to post the same question not 30 seconds before you did.

From what I gather... Here are some of the big ideas that I've seen that cover the RPG/Zelda style look.

Here is an idea to use a double-linked list to do y-axis ordering:
http://www.garagegames.com/mg/forums/result.thread.php?qt=36316

This also works for Isometric-style games like Diablo and Starcraft.

Here is another thread that covers how to change the draw order of a sprite within a layer:
http://www.garagegames.com/mg/forums/result.thread.php?qt=27613

But I think the most interesting idea was a small fix to the actual engine itself covered in this thread:
http://www.garagegames.com/mg/forums/result.thread.php?qt=37339

The last one seems like the easiest idea to do a y-axis sort and it involves a simple change to the Torque engine code, but the last time it was updated was way before Beta 1.1, so I'm not sure if it applies any more.

So I was wondering if any gurus could help us on this? It would me much appreciated.
#2
03/14/2006 (10:10 pm)
Awesome, thanks for the last link! i dont know how i missed it. he said it was updated for 1.1 alpha, i wonder how much has changed since then??
#3
03/14/2006 (10:53 pm)
Here's a copy and paste of some of my older posts :)

Another way is to attach it to an object... most commonly would be either a SimSet or a ScriptObject

like this

new ScriptObject(gameData);

gameData.score = 1000;

gameData.save("starter.fps/data/saves/gameData.cs");

this will create a script object, set its "score" value to 1000, then save it out to gameData.cs... the file will look like this

//--- OBJECT WRITE BEGIN ---
new ScriptObject(gameData) {
      score = "1000";
};
//--- OBJECT WRITE END ---

then you can exec() the file like this

exec("starter.fps/data/saves/gameData.cs");

and can access the script object now

echo(gameData.score);

SimSets will hold objects, so you could create one like this

new SimSet(game);

then add gameData to it

game.add(gameData);

then save out the game SimSet like this

game.save("starter.fps/data/saves/game.cs");

the outputed save file will look like this

//--- OBJECT WRITE BEGIN ---
new SimSet(Game) {

   new ScriptObject(gameData) {
         score = "1000";
   };
};
//--- OBJECT WRITE END ---

to load it back in you would use an exec command like this

exec("starter.fps/data/saves/game.cs");


You can iterate through a SimSet like this :)

%count = game.getCount();

for(%i=0;%i<%count;%i++)
{
   %obj = game.getObject(%i);
}
#4
03/15/2006 (2:27 am)
Thanks Matthew, I didn't know about SimSets. Any info on the y-axis rendering that's more up to date than the posts I found?

Maybe y-axis rendering should be a default setting or something for TGB since so many 2D games use it like isometric rendering and 2.5D games like RPGs.
#5
03/15/2006 (2:59 am)
These Y-Sort methods are a bit old.
If you are able to modify the source code and recompile TGB then it is fairly easy.

Create a file called SceneGraphYsort.cc or something like that, copy the following code into that file, add it to your Visual Studio Project and recompile.

#include "platform/platform.h"
#include "console/console.h"
#include "T2D/t2dSceneGraph.h"


static S32 QSORT_CALLBACK isoRenderSortFn(const void* a, const void* b)
{
	// Sort by Y - coordinate
	const t2dSceneObject& objA = **((t2dSceneObject**)a);
	const t2dSceneObject& objB = **((t2dSceneObject**)b);

	return (objA.getPosition().mY + objA.getHalfSize().mY) - (objB.getPosition().mY + objB.getHalfSize().mY);
}

ConsoleMethod(t2dSceneGraph, activateIsoSort, void, 3, 3, "(%state) Activates sorting by Y-Coordinate")
{
   const bool activate = dAtob( argv[2] );
   
   object->setRenderSortFunction( activate ? isoRenderSortFn : t2dSceneGraph::layeredRenderSort );
}

You should then be able to activate Y sorting by calling something like this from script:
$yourSceneGraph.activateIsoSort( true );

I have not tested it but it should work like that. Copy-paste-recompile. Tell me if it doesn't work.

-Michael
#6
03/15/2006 (5:50 am)
@Matthew: thanks a bunch, that explains it a little better. so a SimSet is basically like an array for objects? or am i totally off here...?

@Michael: ok, that sounds cool. i'll try it when i get home from work tonight.

my only question is this: what happens in a situation where something higher on the Y should be in front of the character regardless of his Y coords? for instance, i want to mount the camera to the player, but when he walks through doors i believe hed be rendered overtop the wall above the door because hes considered lower on the Y axis. would there be a way to define layers that are always above regardless of Y?

thanks to everyone for their help!!
#7
03/15/2006 (6:03 am)
Quote:
would there be a way to define layers that are always above regardless of Y?

Yes. Sorting only happens within the same layer. An object in layer 0 will always be render after an object in layer 1. (or the other way round?)
#8
03/15/2006 (8:50 am)
Isn't it just easier to do the sorting via layers? Or is 32 not enough for the game you are wanting to make?

Quote:
An object in layer 0 will always be render after an object in layer 1. (or the other way round?)

That's right, an object in layer 0 will render 'on top' of layer 1.
#9
03/15/2006 (11:04 am)
Honestly, i think my algorithm is much more desirable than the code hack described.

Though a better solution would be to work off of the code hack, and let you programatically modify the render level (instead of forcing it to be based on Y)
#10
03/15/2006 (11:18 am)
What is your algorithm?
#11
03/15/2006 (11:50 am)
Yes yes, do tell :)
#12
03/15/2006 (2:07 pm)
My algorithm (psudo algorithm) is simple, and it's described in the first post that Paolo mentioned.

And while that engine hack gives a quick fix, it breaks your control of any sort order, which is probably a bad thing for you as a game developer.

Dont get me wrong... that engine hack is a good place to start. The information it tells you is more than enough to implement a custom sort-order programatically.

Though is it better performance than the algorithm I described? Meh.. probably, but not by that much I bet, and for people who dont know the C++ code much, you can implement what I described in torquescript.

-Jason
#13
03/15/2006 (2:35 pm)
I think your algorithm is too complicated for this easy task. If you only want to use torque script then ok but otherwise I would use what I wrote above. It's easily extendible to provide more control.

I don't think performance will ever be a problem. You cannot have so many sceneobjects that sorting them is a noticable problem before their physics- and other updates become the real performance bottleneck.

I think, this is really such a small and non-performance critical issue that the solution is just a question of preference. :)
#14
03/15/2006 (6:03 pm)
Michael: I tried to compile that and i got 3 errors (I'm using Xcode by the way):

JamToolExecution Torque2D-MacCarb-Debug (1 error)
- Command /Developer/Private/jam failed with exit code 1

Compiling ../../../games/T2D/SceneGraphYsort.cc ( 2 errors)
In function 'S32 isoRenderSortFn(const void*, const void*)':
- error: 'getPosition' undeclared (first use this function)
- error: 'getHalfSize' undeclared (first use this function)

Sorry if this something dumb, which it probably is. This is my first time trying to compile the engine. Anyway, thanks for all your help!
#15
03/15/2006 (8:21 pm)
@James: Assuming what you are saying is literally true: I dont mean to be overly critical here, but it is very, very important that you take discreet logical steps when doing any type of troubleshooting. The first step should be to get the engine building before making these modifications. Then once that works, (and you test and make sure it works) then you make the additional code changes.

@Michael: I think the code you wrote is GREAT, because it shows people very clearly where to modify the engine code to programatically control the render order. But as far as functionality goes, I foresee a lot of times where relinquishing render order is going to be very bad for developers.... but if they make your change, they can easily figure out how to tweak it to their liking.
#16
03/15/2006 (9:09 pm)
@Michael:

Does your code sort everything in the SceneGraph by y-axis or does Layers take precedence? I wonder if there is a way to tweak the code so that instead of specifying if you want an entire SceneGraph to be sorted on the y-axis you can specify specific layers to be sorted. I don't quite understand the C++ enough yet to really make modifications on my own.

By the way, is there any sort of code walkthrough material on the site to give us a breakdown of how the C++ is organized?

I so wish I could attend that TGB bootcamp...
#17
03/15/2006 (9:16 pm)
Paolo: from what they said, it sorts each layer by the Y, so if you have something on layer 0 it will still be in front of layer 1. i'm trying to figure out why its not compiling :(
#18
03/16/2006 (1:28 am)
@James:
Sorry for causing trouble. Add this line somewhere at the top:
#include "T2D/t2dSceneObject.h"

then it should work. At least on Windows it compiles fine.

@Paolo: James is right.

@Jason: Yeah. I see your point. But this is only thought for this 3/4 top down perspective games. I have programmed games like that before I used TGB and used the same method with the difference that I replaced the getHalfSize().mY with a value that I could modify for each sprite. This turned out to be flexible enough for everything I needed.
#19
03/16/2006 (5:46 am)
Thanks! I'll try it tonight when i get home from work.
#20
03/16/2006 (7:04 am)
Maybe I should add a in-layer y-axis sort as part of a wish list before the final release.
Page «Previous 1 2