Game Development Community

Change a background tiles image on the fly

by Jeff Trier · in Torque Game Builder · 07/31/2005 (2:03 pm) · 2 replies

I have been poking around for most of the day trying to figure out how to change a background image on the fly.

Basically what I have done was create a fxTileMap2D object that is 16x16 tiles in area. What I need to do is have a mouse selected tile change it's image.

Here is the code I am messing with:
function CreateTileMap() { 
   //Create tile-map.
   $playMap =new fxTileMap2D(){scenegraph =t2dSceneGraph;};

   //Load saved tile-map file.
   $playMap.loadTileMap("~/client/maps/dungeon.map");

  ...removed for brevaty
}

// select the tile under mouse
function sceneWindow2D::onMouseDown( %this, %mod, %worldPos, %mouseClicks ){

   // get tile layer (works)
   %id = $playMap.getTileLayer(0);

  // get x,y loc of selected tile (works)
   %xy = %id.pickTile(%worldPos);

   // change tile at selected locations image
   


   echo(%xy SPC %id.getTileType(%xy));
}

My real problem is that I can't seem to figure out how to grab a pointer to the tile object itself, and/or utilize the setImageMap() command to swap the image tile.

Can anyone point me in the right direction?

Thanks in advance!
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
07/31/2005 (3:16 pm)
Have a look at setStaticTile() or setAnimatedTile() in the docs. They should do the trick.
#2
07/31/2005 (3:54 pm)
Woo Hoo!

Thanks, that did the trick!

-Jeff