Game Development Community

Dynamically changing tile images

by Joseph Albon · in Torque Game Builder · 03/03/2005 (7:10 pm) · 6 replies

Hi all, I've hit a major snag on my current project. That's somewhat amazing to me due to how easy the engine has been to use so far once you figure out all the function calls.

My issue is this: Due to the nature of my project, the world is made up of a 4 layered tilemap. The very bottom layer uses single colored squares and the rest of the world is built on top of that. As each square is a single color I was hoping to be able to just slap down white tiles in bulk and then using setBlendColour to update the cells individually.

The issue I'm having is I have no idea how to do that with a tile in a tile map. I already have the player image blending correctly, but the tile map seems beyond my abilities. I'm not sure if I'm just missing something, or if it's not possible without digging down in to the source code.

Anyone have any ideas?

If all else fails I'll just make a new graphic for each background color I need, but thought that I might be able to apply simple lighting effects if I could just use a blending color.

#1
03/03/2005 (7:14 pm)
I dunno for sure, but you probably have to first get access to the tile in question. You can look at fxTileLayer2D (which you can get to via fxTileMap2D) to grab tile info. Then you could use the setBlendFunction() etc to change the colors. I think?
#2
03/03/2005 (7:29 pm)
I tried using pickTile, but the results weren't what I was expecting.

I echo'ed a getClassName() on the returned object to see what I was dealing with, some of them are fxChunkedImageDatablocks, some are fxCollisionMaterialDatablock2Ds, and some fxImageMapDatablock2Ds.

I'm not sure if that's what I should be getting, or if I'm doing something horribly wrong.
#3
03/03/2005 (7:30 pm)
Just digging throuhg the documentation

Quote:

setStaticTile() Sets a Static Tile. (int tileX / int tileY, imageMapName$, [frame]) tileX/Y Selected Tile.
imageMapName fxImageMapDatablock2D object name to use for the static tile.
frame Frame to use from the specified "imageMapName". Default is 0.
#4
03/03/2005 (7:33 pm)
@Matthew - saw that one too. The only problem is my image map name is a constant, just a white image. I'm trying to alter that default image with a blending color, so I need access to a fxSceneObject it seems.

Basically that call would be:
setStaticTile(%x SPC %y, "whiteImageMap");

which would result in exactly what I started out with.
#5
03/04/2005 (2:25 am)
@Joseph: Using the tilemaps for a single-coloured background is a very expensive way to go. Use a standard background control with a bitmap or something would be better.

You can't have individual tile blending options at the moment although I have toyed with doing this. Adding this is pretty easy but it would definatley have an impact on performance. That's the balance I'm trying to find here, adding features for people without affect performance for those who don't want it.

I've deferred the work until a later date until I do the work that sorts tile-renders by texture/blending options so that they can be batched to the GPU and keep the state-switching to a minimum.

At the moment though, any fxSceneObject2D and this includes the fxTileLayer2D can have there own blending functions using "setBlending()" and "setBlendColour()" but that applies to the whole object.

Sorry if this causes you problems in the short-term but it is definately a feature I'd like to see in there, also under editor control.

EDIT:- Just re-read your post about simulating lighting and understand why you're doing what you're doing. A bit of a hack but if you're not scrolling the tilemap, you can mount static-sprites to it for lighting but I don't think that'll be the best way to go or that efficient if you're doing hundreds/thousands of these although you would be able to rotate them for nicer more precise lighting effects like spinning emergency lights etc.

- Melv.
#6
03/04/2005 (4:09 am)
Thanks Melv!

I'm glad I wasn't missing something simple at least.

I'll take a look at mounting static light points to my map, I can't imagine there will be too many of them.

Time to whip up some one pixel images I guess, good thing that's still barely within my artistic abilities.