与FlashPunk的碰撞检测套件

时间:2014-10-25 19:08:52

标签: actionscript-3 flash collision-detection

我开始使用Flashpunk创建我的Flash游戏,对于我不想使用hitbox的碰撞,因为我有图像(PNG),其中有透明部分所以我决定使用碰撞检测套件,我有一个问题创建碰撞列表,它将显示对象作为参数,并且不接受flash punk spritemaps,我试图将spritemap强制转换为flash显示对象,但是它没有工作,有没有办法使用CDK与flashpunk?

override public function begin():void 
    {

        _player = new Player(100, 100);// Entity

        initCollision(_player.sprPlayer);// The Entity Spritemap
    }


private function initCollision(player:Spritemap):void {

        collisionChecker = new CollisionList(player); // Problem here

    }

1 个答案:

答案 0 :(得分:0)

好吧,你可以创建一个宽度相同的空BitmapData。你的Spritemap的高度然后"渲染"它就像那个BitmapData一样:

var bmd:BitmapData = new BitmapData(64, 64, true, 0);
var sprite:Spritemap = _player.sprPlayer;
sprite.render(bmd, new Point(0,0), new Point(0,0));
collisionChecker = new CollisionList(bmd);

那应该将spritemap的当前帧绘制到BitmapData,然后可以将其用于CollisionList。上面的代码是一个示例,仅演示如何执行此操作。对于您的实际代码,最好避免在碰撞检测期间不断初始化新变量。