Game Development Community

dev|Pro Game Development Curriculum

Swan Song - Isometric T2D Project

by Simon Love · 07/14/2015 (4:00 pm) · 10 comments

Greetings, fellow Torquers!

Last month I decided to create a game in a month. AH! No matter the results, you, the audience, will reap the fruits of my hard labor and be thankful for it!


Isometric Tile Editor


First up, I made an isometric map editor.

www.s01l.com/repository/screenshot12.png
How to make CompositeSprite handle Isometric Maps, where 0,0 is in the upperLeft corner?

function Isometric::onCustomLayout(%this, %logicalpos)
{
   //As long as we keep the correct ratio!

   %TilesizeX = Level.LevelInfo.BaseTileSize.x;
   %TilesizeY = Level.LevelInfo.BaseTileSize.y;
   
   %logicalX = getWord(%logicalpos,0);
   %logicalY = getWord(%logicalpos,1);
   %LogicalZ = getWord(%logicalpos,2);
   
   %x = (%logicalX/2 * %TilesizeX) - (%logicalY/2 * %TilesizeX);
   %y = (%logicalY/2 * %TilesizeY) + (%logicalX/2 * %TilesizeY);
   %y -= %TilesizeX * %LogicalZ;
   
   return(%x SPC -%y);
}

In my case, I skip the next-to-last line as each layer of my map sits on an independent Composite Sprite for added flexibility.

SceneLayerDepth


The tricky thing with Isometric perspectives is the order in which tiles are drawn; it gets even trickier when you have objects moving through these tiles. I use BatchSortMode = "Z" which draws items based on their SceneLayerDepth.

Results are that the lower-right tile is at SceneDepth 0.00, the tile to its left 0.01, 0.02,0.03. When we change rows, the tile to the extreme right is at 1.00. This makes Isometric tiles draw correctly.

function Isometric::calculateDepth(%this, %position)
{
   %fraction = (Level.LevelInfo.MapSize.x-1) - %position.x;
   %fraction = %fraction/100;
   
   %unit = (Level.LevelInfo.MapSize.y-1) - %position.y;
   return(%unit + %fraction);
}

In my setup, Switching layers is not problem, since each layer exists as a separate Composite Sprite on its own scenelayer so we just change SceneLayers, keep the same SceneLayerDepth.

Lighting


www.s01l.com/repository/screenshot5.png
As you can see in the above screenshot, I tried my hand at a very simplified Lighting system. I simply calculate a radius around each candle and fade out with each ring. The lighting is applied via the SpriteBlendColour. Problem is that a sprite cannot be partially lit so directional lights and shadows are completely incoherent. Cool effect but highly impractical.

Screenshot functionality


www.s01l.com/repository/screenshot10.png
How did I take all these screenshots? Directly from T2D, of course!

Here is the entire script for doing so. It will save screenshots to a directory (which you can specify with $pref::Video::ScreenShotDir) and increment the filename so that nothing gets overwritten.

Just put this in a script file and exec it. Call init_Screenshot at the start of your game and ta-dam!

GlobalActionMap.bindCmd("keyboard", "F5", "do_ScreenShot();", "");

if($pref::Video::ScreenShotDir $= "")
   $pref::Video::ScreenShotDir = "Screenshots/";

function init_ScreenShot()
{
   %filelist = getFileList($pref::Video::ScreenShotDir);
   %count = %filelist.count;
   $ScreenShotSuffix = %count;   
}

function do_ScreenShot()
{
   screenShot($pref::Video::ScreenShotDir @ "screenshot" @ $ScreenShotSuffix @ ".png", "PNG");
   $ScreenShotSuffix++;
}

Asset Tags


Sorting Assets is hard but thanks to the wisdom of T2D's creators, there is a rather elegant way of doing so.

In your Assets definition module (ToyAssets for instance), add the following line at the end of your module.taml file

AssetTagsManifest="^MyModule/AssetTags.Manifest.taml";

The file should be an XML file structured as such

<AssetTagsManifest>
    <AssetTagsManifest.Tags>
        <tag
            Name="Traps" />
    </AssetTagsManifest.Tags>
    <AssetTagsManifest.Assets>
        <tag
            assetID="PlatformerAssets:FloorIzLava"
            Name="Traps" />
    </AssetTagsManifest.Assets>
</AssetTagsManifest>

In Tags, you specify all your tags, in this case, "traps".
Under Assets, you associate a declared asset with a specific tag.

In your game script, load the asset tags as follows

%AM = AssetDatabase.getAssetTags();

You can then perform sorting and filtering operations with tags.

In my case, I wanted to see if an image asset had the Traps tag associated with it.

if( %AM.hasTag(%assetID,"Traps") )
{
//do something clever.
}

Make sure to read the WIKI for functions to try.

Closing Comments


There you have it, a few quick tips for those still using T2D. It would be extremely laborious to get into the details of the editor and of everything I've done but if you guys have questions on any aspect. Feel free to ask!

About the author

I am here to help. I've worked at every imaginable position in game development, having entered the field originally as an audio guy.


#1
07/15/2015 (6:06 am)
You've been attacked by the forum quote translation bug - you edited this post, didn't you?

Awesome stuff! As usual.

Thanks for sharing, Simon.
#2
07/15/2015 (6:29 am)
Fixed! Thank Richard, I wasn't aware that Editing a post after the fact was the reason for this bug.

Your vigilance is the stuff of legend. Thanks for the good word.
#3
07/15/2015 (7:04 am)
Awesome stuff! :O) Too sad I have no time for Torque 2D. I really like the isometric view.
#4
07/15/2015 (10:52 am)
Nice work, Simon!
#5
07/15/2015 (10:57 am)
Thanks for the kind words, y'all!
#6
07/15/2015 (5:51 pm)
Yeah, it seems to only strike blog posts - the forums themselves seem immune to the &quot;Issue&quot;.
#7
07/16/2015 (9:39 am)
This is badass! Each project/contribution you make is more impressive than the last. Nicely done Simon =)
#8
07/16/2015 (9:41 am)
If only there was a market for half-finished, Windows-centric prototypes :)

Thanks Mich! Hope you're having a great summer!
#9
07/17/2015 (5:53 pm)
July highlight? Check.

Really glad to see another blog from you Simon. Great stuff here - half finished or not. :-)
#10
07/17/2015 (7:32 pm)
My goal is solely to entertain you, Mike!

Sometimes it really does feel like the only reason I do this is to share it. All about T3D this month though.