开发者

How to properly use hitTest between bitmapData and an object?

I have converted a PNG into a bitmap, then converted that into bitmapData.

I have a object cal开发者_JAVA技巧led _player, and I wish to add collision detection, however I can seem to get it to work.

my code is:

if(bmd1.hitTest(new Point(_player.x, _player.y))){
trace("hit");
}

bmd1 is my bitmapData,_player is the object is wish to test against.

I am getting the following error:

1136: Incorrect number of arguments, Expected 3

I have looked around but cannott find what argument I am missing

Any ideas?

Update

I have tried

if(bmd1.hitTest(new Point(_player.x, _player.y), 50, _player)){
trace("hit");
}

with no joy

Update 2

Sorry, I should mention that the reason for me taking this approach is that I have a PNG, with transparent areas, I need to test for collisions in the non-transparent areas, which is why I was using this approach

I have a PNG, i import that and convert to bitmap, then convert to bitmapData

I maybe doing this completely wrong. Could you show me where the problem lies?


hitTest has 3 mandatory arguments:

public function hitTest(firstPoint:Point, firstAlphaThreshold:uint, secondObject:Object, secondBitmapDataPoint:Point = null, secondAlphaThreshold:uint = 1)

Check the doc


In the end I converted my player movieclip to bitmapdata, converted my png map to bitmap data, then used hitTest to check the x and y of each bitmap against each other


The method you want is hitTestPoint() not hitTest()

EDIT: whoops I missed that you were doing the hit test against BitmapData instead of a DisplayObject. BitmapData.hitTest() performs pixel-level detection which is pretty slow in many situations. You're probably better off putting the BitmapData into a Sprite and then using hitTestPoint()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜