"Custom grid" + functions (using a global list for reference and fast changes)

Red Frostraven

  • Posts: 23
I could not be bothered to use the ingame grid, because I'm making a game with 1024x576 screen size that needed a grid that could not be fit to the scene with the current resolution and using a static grid size, without going for 4 pixel grid sizes.
So I made a custom grid reference behavior that utilizes custom blocks and global lists (of it's user's choice) to create custom grids within scenes.
Tiles start at 0,0 -- so 10x10 tiles start at 0,0 and end at 9,9.

Base settings:
-Set tile height and width
-Set grid offset/start (I did not want my grid to start at 0,0, so I made the ability offset the start of the grid to anywhere as a X,Y position.
-Set grid's width and height in tiles

Note that these values can be changed at any time, altering the functionality of the grid on the fly,  resizing tiles, expanding the number of tiles or moving the grid in any direction.
I used three separate global blocks, where all three are required to be set for the grid to work.

Grid offset X,Y and grid width and height can all be set to 0 to create a grid that starts at 0,0 and continues infitely.

Grid offset X,Y can be set to 160, 100 -- for instance -- in order to make a grid that has it's 0,0 tile position starting at X160,Y100
Grid tile width and height can be set to 5,5 to create a grid that is only 5 tiles wide and 5 tiles heigh.

You can create as many custom grids as you want within one scene for as long as you can keep track of your global lists the functions refer to.

Basic functionality:
-Translate X position within grid to the corresponding tile Row (returns -1 if the position isn't on grid)
-Translate Y position within grid to the corresponding tile Column (returns -1 if the position isn't on grid)

Theses allow you to translate the positions of actors into coordinates on the grid, or get the tile the mouse was clicked on.

-Translate center of Row number to X position
-Translate center of Column number to Y position

This reverses the translations of positions to grid tile numbers, by returning the X and Y positions of the CENTER of tiles specified.
For instance, 4x and 4y in a 100x100 grid tile will return X 550 and Y 550.
(Grid tiles start at tile 0,0.)

Semi-advanced functionality:
Translate X,Y positions into center of the appropriate tile's X,Y positions (snap to grid)

Example: If I click the mouse to move a character to a position, the function changes an input of X,Y to the the tile at X,Y's position's center X,Y coordinates.
If our grid has 100x100 pixel tiles with a X150,Y80 offset and a player clicks on the position X282 and Y198 -- it calculates that the player clicked on Tile 1,1, and returns X300 and Y230 -- the center of the grid tile that was clicked.

Is X,Y position on grid? (Returns true if X and Y positions are on the grid)


If anyone wants this behavior, just tell me -- and I'll publish it.
Publishing it just requires me to rewrite to the functions to employ human language and adding descriptions.

Speaking of which..: is there any way to change the custom blocks themselves or add descriptions after creating the blocks?

« Last Edit: April 14, 2013, 03:50:02 am by Red Frostraven »


  • *
  • Posts: 9474
You can right click the custom block to change the display and description, but if you need to add new parameters you'll have to create a new custom block.

Red Frostraven

  • Posts: 23
Yeah. The most important part is the description.

I caught MYSELF getting confused by the block names :D
Adding a description should do it.