Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

is it possible to add a hit test to object class, like a tile, if so how would approach this

Community Beginner ,
Sep 22, 2018 Sep 22, 2018

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.hitTestPoint(player.x +10,player.y, true)){

health--

//trace(health)

moveSpeed = 1

}

that would be inside of an ENTER_FRAME

TOPICS
ActionScript
290
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018

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] ];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 22, 2018 Sep 22, 2018

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2018 Sep 22, 2018
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines