Game Development Community

Displaying a tile with a lower size

by Pedro Vicente · in iTorque 2D · 09/11/2011 (4:25 pm) · 7 replies

I was wondering if there is any way in script to display a tile so that it does not occupy the full area in the tile map grid.

Better seen in this image: I want to leave a blank space between each tile so that they are not together

iphone4 screenshot:

www.space-research.org/games/garage_games/127717.png



function OptionsSceneGraph::CreateWordSizeTileLayer(%this)
{
   %this.WordSizeTileLayer = new t2dTileLayer()
   {
       class = "WordSizeTileLayerMouse";
    }; 
   %this.WordSizeTileLayer.setUseMouseEvents( true );
   %this.WordSizeTileLayer.createLayer(  %this.tileCountX, %this.tileCountY, %this.tileSizeX, %this.tileSizeY ); 
   %this.WordSizeTileLayer.setSize(  %this.tileCountX * %this.tileSizeX, %this.tileCountY * %this.tileSizeY );  
   %this.WordSizeTileLayer.setGridActive( 0 ); 
   %this.WordSizeTileLayer.setPosition( 0, 0 );  
   %this.WordSizeTileLayer.setLayer( 18 ); 
   %this.getGlobalTileMap().addTileLayer( %this.WordSizeTileLayer ); 
}

#1
09/12/2011 (10:48 am)
@Pedro, might be easier to put some space around the image ?
#2
09/12/2011 (11:33 am)
Yes, I do not understand what you are trying to do here.

if this grid, typographic is a tileMap and where 0 represents and empty space and 1 is an object, filled space....
//01//00//01//
//01//00//01//
//01//00//01//


???

#3
09/12/2011 (11:34 am)
Scott, right; easy fix :-)
#4
09/12/2011 (11:49 am)
@rennie
I was trying to achieve this effect:


www.space-research.org/games/garage_games/127717_2.png
But like Scott mentioned the simplest way to do this is just leave some empty background in the original image: in the first post the color occupies all the image dimension 128x128; in the second image the image is still 128x128 but the color just occupies 118x118, so the rest is transparent :-)

Regarding user interface that still leaves a 10 pixel empty space that responds to the touch/mouse; but most users will probably just tap the center :-)

Other option: just do a cycle of t2dStaticSprite instances, but tile layer is best prepared for these grid like effects.
#5
09/12/2011 (1:18 pm)
Yah, some of the best tricks are just optical illusions.





Just a quick question, with a tileMap, is each tileBit mouseSensitive? If not each one is programmable, as in, you can change tile1-3 from holding numberImageMap, frame 1, to frame 2 correct?






#6
09/13/2011 (10:27 am)
@rennie

yes, each tile can respond to mouse with the pickTile function. There is also a setTileScript for programmable actions, but I never tried it. The t2dTileLayer class has a great amount of functions but I usually only use setStaticTile (draw a tile) and clearTile (erase), since all my grid game logic is mostly in C++.

There are 2 ways that you can attach an image to the tile:

1) Do a t2dImageMapDatablock where the class is CELL type, and then call setStaticTile with the cell (frame) index

2) Do a t2dImageMapDatablock where the class is FULL type, and then call setStaticTile with the index 0 always; I usually use this just because it's easier to have individual images; that's what is done in the code here

new t2dImageMapDatablock(Tile_Padded_01_ImageMap) 
{
      imageName = "data/images/set_02_tile_blue_padded_96.png";
      imageMode = "FULL";
      filterPad = "1";
};


function OptionsSceneGraph::DrawGrid(%this)
{
   //number of tiles: minimum word size starts at 3
   %counter = 3;
   
   
   // draw by rows
   for ( %y = 0; %y < %this.tileCountY; %y++)
    {
       for( %x = 0; %x < %this.tileCountX; %x++)
       {
          
          if ( %counter > %this.word_size_options )
          {
             break;
          }
          
          if ( %counter == $model.word_size )  //selected word size
          %this.WordSizeTileLayer.setStaticTile( %x, %y, Tile_Padded_02_ImageMap, 0 );
          else
          %this.WordSizeTileLayer.setStaticTile( %x, %y, Tile_Padded_01_ImageMap, 0 );
          %ID = %this.TextObjArray.get( %counter - 3 );  //starts at 0
          %ID.setPosition( getTileCenter( %this.WordSizeTileLayer, %x, %y  ) );
          
          %counter++;
             
      }
    }
}
#7
09/13/2011 (12:36 pm)
Thanks Pedro , I appreciate that.



::)||