PDA

View Full Version : [AS3]hitTesting a lot of tiles



flashmxboy
July 30th, 2009, 02:52 PM
Hi guys:hugegrin:

I`m (still:emb:) working om my platformer. And i used bitmaps to do destructable terrain. Sadly bitmaps cant be bigger than 2880 X 2880:hair: So i finaly got a way to tile my level MC up in smaller bitmaps( with some help from this forum) Now doing this totally messed up my hitTesting. I was hitTesting for one bitmap. But now i have like 20.
So i thought grouping them together somehow would be the most efficient.
So i tried to add all the tiles to a movieClip:
ground.addChild(arrayOfTiles[row][collum]);
But if i used regular hitTestPoint on the ground MC it detects hits on the boundinBox because the bitmaps are filled with pixels:(
So i tried with the Collision Detection Kit. It worked, but was way to CPU heavy(mabye i used it wrong??)
So im kinda stuck:S

Any ideas??

Edit: I figured out i should put a screenshot on the hitTest thing...just to dont leave you guys with nothing...
This is using regular hitTestPoint and having the bitmaps added to a MC:
http://nettvei.com/whitePixels.JPG

therobot
July 30th, 2009, 03:15 PM
I can't help you with your bitmap collision detection, but I will mention that you shouldn't need to check collisions in every single bitmap tile - you just need to keep track of which one your character is currently in, and check that one.

flashmxboy
August 3rd, 2009, 08:22 AM
Hi again.

Yeah i probably shouldn't hitTest all the tiles, so i thought out a simple system for hitTesting. :
The following was the orginal plan for the system. I like to visualize things with picutes:P :
http://nettvei.com/clipRect.JPG
And if the tiles dosent hit the vcam.
http://nettvei.com/clipRect2.jpg
Also the plan was that the bitmap should be as big as the vcam, and follow the vcams position.

But i cant seem to get this work.
Heres a stripped down version of the code i use:
//This works

//Notice i make the bitmapData 2880 x 2880 pixels. I cant get it working if i dont.
var bmd:BitmapData = new BitmapData(2880, 2880, true, 0xFFFFFF);
//Just an example rect
var rect:Rectangle = new Rectangle(0,0, arrayOfTileBitmaps[2][2].width, arrayOfTileBitmaps[2][2].height);
//I set the destination point to the upper left corner of the tile.
bmd.copyPixels(arrayOfTiles[2][2], copyRect, new Point(arrayOfTileBitmaps[2][2].x, arrayOfTileBitmaps[2][2].y));

//This dosent work:

//I think the problem is here. When i set the bitmapData to match the width and height of the vcam everything messes up...
var bmd:BitmapData = new BitmapData(vcam.width, vcam.height , true, 0xFFFFFF);
//Just an example rect. I set the x and y values to the upper left corner of the tile
var rect:Rectangle = new Rectangle(arrayOfTileBitmaps[2][2].x, arrayOfTileBitmaps[2][2].y , arrayOfTileBitmaps[2][2].width, arrayOfTileBitmaps[2][2].height);
//I set the destination point to the upper left corner of the tile.
bmd.copyPixels(arrayOfTiles[2][2], copyRect, new Point(arrayOfTileBitmaps[2][2].x, arrayOfTileBitmaps[2][2].y));
//Note: i didnt write the code that makes bmd follow the vcam


Any ideas??
Thanks in Advance.

therobot
August 3rd, 2009, 02:29 PM
I don't quite understand what your problem is.

I strongly encourage you to read this tutorial: http://www.8bitrocket.com/newsdisplay.aspx?newspage=17214

Essentially you need to figure out which bitmapdata tiles will be in your camera, then figure out where you need to start copying and pasting them from. That tutorial I linked to covers this process quite well. It's long, but it's very informational :)