3

Normally, an Axis-aligned (rotation = 0) tilemap is easy to iterate through the visible tiles on the screen.

But how do you "cull" or filter the tile indexes when the entire tilemap is rotated?

enter image description here

NOTE: This is for improving a tile-rendering class in ActionScript 3.0 (in Genome2D), but answers in other computer languages could just as well be applicable! :)

chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
  • I'm not pretty sure what you exactly need, as 'cull', 'filter' and 'look-up' are extremely different things. Anyways, seems like a matrix would do all kind of work, as it will rotate and modify your input values (x,y). – Andrey Popov Mar 27 '14 at 11:22

1 Answers1

0

I'm not 100% clear on what you're trying to DO with each of the tiles, so I'll assume you want to find which ones to render and which ones not to.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestObject()

You can try to set up a dummy object on the screen and do this:

For each tile in tilemap
    if (dummyScreenObj.hitTestObject(tile))
        tile.visible = true
    else
        tile.visible = false
MZA
  • 91
  • 5
  • I'd prefer to avoid checking each invididual tiles. What I'm after is a way to set boundaries for an outer and inner for-loop (like you would normally use for an axis-aligned oriented tilemap), but that would iterate on sloped / scaled tiles as well. For example, instead of using `for(var c=columnStart; c<=columnEnd; c++)` and `for(var r=rowStart; r<=rowEnd; r++)`, it would iterate `for(var sc=slopedColumnStart; sc<=slopedColumnEnd; sc++)` and `for(var sr=slopedRowStart; sr<=slopedRowEnd; sr++)`, but would obviously require some math to figure out the tile-indexes. Does that make more sense? – chamberlainpi Apr 30 '14 at 13:14
  • I'm not so sure your goal is attainable. For your example, each row has a different number. This will always change depending on the rotation as well. For example, now you have a row 2 long, followed by 4, 5, 6, 6, 6, 5. – MZA May 03 '14 at 00:27
  • If you don't want to go through the actual tiles individually, you could create a whole dummy copy of empty mc's mapped to the real tiles and test against those. – MZA May 03 '14 at 00:29