Problems setting up collision with new object
Hi guys,
I'm developing a shoot 'em up game where if the player kills enemy, the enemy turns to a block (block is a new object replacing enemy - enemy is removed from the stage) and the player will be able to push the block around the level.
For some reason, I can't seem to setup the collision on the new block object that appears on the stage, I using the same code structure/idea for bullet detection on enemy but doesn't seem to function. I was wondering if anyone would know what I'm doing wrong or any suggestions to fix/work around? Here goes....
I have 3 classes/documents -
Block Class - Properies for the block object
Main Class - logic and core features of the game
Collision Class - Collision properies and setup
- Block Class -
Code:
private function onEnterFrame(event:Event):void
{
MovieClip(parent).checkCollisionWithPlayer(this);
}
- Main Class -
Code:
function checkCollisionWithEnemies(bullet:MovieClip)
{
var block:Block = new Block();
block.x = enemy.x;
block.y = enemy.y;
{
if (enemy.meter.width < 1)
{
enemy.stop();
swapProperies(enemy,block);
removeChild(enemy);
enemy = null;
addChild(block);
}
function checkCollisionWithPlayer(block:MovieClip)
{
if (player!= null)
{
Collision.block(block, player);
}
I'm using the Collision.block(block, player) method call using the Collision class/doc, this works fine with collision between player and enemy, not why for this new object: block as shown below:
- Main Class -
Code:
function onEnterFrame(event:Event):void
{
if (player.hitTestObject(enemy))
}
Collision.block(player, enemy);
}
The only difference is that it's within a different function of onEnterFrame instead of heckCollisionWithPlayer, surely that shouldn't make a difference?
Anyways any help or suggestions would be greatly appreciated.
Thanks
Jonesy