Copy link to clipboard
Copied
this is the way that I do a hit test inside a time line actionscript, but it takes a lot processor if there is a lot of tiles. so then I was wondering if I could skip the loop and add it dirctly to the tiles class. But I don't think variables are possible to pass back and fourth.
for (var r=0; r<tileholder.length;r++){
if(tileholder
health--
//trace(health)
moveSpeed = 1
}
that would be inside of an ENTER_FRAME
Copy link to clipboard
Copied
you wouldn't do usually add a hittest to an tile class (assuming the tile class is the class of a single tile).
you can usually streamline a loop like that by looping through the tiles in a rectangle 'near' player.
Copy link to clipboard
Copied
so I would put all tiles in multiple arrays and put all those arrays in another array? and use hit test to pull out an array? then use hittest again to pull out the tile?
Copy link to clipboard
Copied
i'd use a 2d array so it's easy (computationally) and fast (computationally) to determine which array elements to check for a hittest.
eg,
var w:Number=tile.width;
var h:Number=tile.height
var tileA:Array=[ [tile at (0,0), tile at (w,0), tile at (2*w,0),..,last tile in top row], [tile at (0,h), tile at (w,h),..., last tile in 2nd row],...,[tile in bottom row left-most position, ..., right-most tile in bottom row] ];
Copy link to clipboard
Copied
do 2d arrays work with isometric? I laid my tiles out in a for loop that had several loops inside of it. The order in which I lay the blocks is important because part of the art work is hidden underneath the brick and rows don't line up the same. odds and evens have a different x value. I think I can figure out how to get the tiles into smaller arrays, through loops it might take me a while to figure the math. maybe I will start with just two and then four and so on
Copy link to clipboard
Copied
wait.
if you're array is already organized in a desirable order, you may not want to create another array for hittests. if your array is organized such that you easily determine the tile's x and y from its array index, you don't need another array for hittests.
if your array is organized in a way that's not easy to determine the x,y from its index, you may want to create 2 arrays. the one you have now and another one for hittests.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now