hi,
sometimes I get this extremely nasty bug:
Code:
ArgumentError: Error #2005: Parameter 0 is of the incorrect type. Should be type BitmapData.
at flash.display::BitmapData/hitTest()
This is the line where I get this error:
Code:
if (player.bitmapData.hitTest(player.point, 255, tempUpgrade.bitmapData, tempUpgrade.point, 255))
I have absolutely no idea what went wrong. My object (tempUpgrade) is generated inside of a manager-class. There I can define the look of it and it
gets cached. The image I use is a spritesheet (png) that's embed inside of my library-class. The spritesheet is splitted into appropriate pics via
a CacheTileSheet-class. After that process they get thrown inside of an array because I need the bitmapData for pixel-perfect collision detection.
Of course this is not the complete code so if someone needs more please let me know. Any help, please?
this is used to determine the look of my object and cache it as well. the CacheTileSheet class is used to split a spritesheet into appropriate bitmapData's so I can throw them into an array (I need this for pixel perfect collision detection)
Code:
public function createUpgradeLook(type:int, cache:Boolean = false):void
{
if (type == 0) {//health
this._width = 256;
this._height = 64;
if (cache) {
imageBM = new Library.PowerUpHealth();
tileSheet = new TileSheet(imageBM.bitmapData, 32, 32, false, 16);
}
}
animationCount = 0;
animationDelay = 1;
cacheType = type;
_type = type;
if (cache) {
cacheSheet = new CacheTileSheet();//here the spritesheet gets splitted into appropriate small parts
allocateCache(cacheType, cacheSheet.cacheSpriteSheet(tileSheet));
cacheSheet.tempCache = [];
imageBM.bitmapData.dispose();
imageBM.bitmapData = null;
}
}
//this is for caching my object
Code:
private function allocateCache(row:int, cache:Array):void {
tileCache[row] = cache;
cache = [];
}
this is for creating the actual object
Code:
public function createUpgrades(xPos:Number, yPos:Number, speed:Number, life:int, level:int):void {
var tempUpgrade:Upgrade = new Upgrade(_xMin, _xMax, _yMin, _yMax);
var reverseAni:Number = randomRange(1, 2);
if (reverseAni == 1) {
reverse = false;
} else {
reverse = true;
}
var randomAni:Number = randomRange(0, 15);
currentTile = randomAni;
tempUpgrade.dx = Math.cos(6.28 * ((Math.random() * 360) - 90) / 360.0);
tempUpgrade.dy = Math.sin(6.28 * ((Math.random() * 360) - 90) / 360.0);
tempUpgrade._type = _type;
tempUpgrade.width = this._width;
tempUpgrade.height = this._height;
tempUpgrade.x = xPos;
tempUpgrade.y = yPos;
tempUpgrade.frame = currentTile;
tempUpgrade.animationList = tileCache[_type];
tempUpgrade.animationCount = animationCount;
tempUpgrade.animationDelay = animationDelay;
tempUpgrade.reverse = reverse;
tempUpgrade.bitmapData = new BitmapData(this._width, this._height, true, 0x00000000);
tempUpgrade.bitmapData = tempUpgrade.animationList[currentTile];
tempUpgrade.nextX = tempUpgrade.x;
tempUpgrade.nextY = tempUpgrade.y;
upgrades.push(tempUpgrade);
}