ActionScript 3的像素完美碰撞。如何? (学习目的) [英] Actionscript 3 pixel perfect collision. How to? (learning purposes)

查看:138
本文介绍了ActionScript 3的像素完美碰撞。如何? (学习目的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有些人在那里创建类本(即的http:// coreyoneil.com/portfolio/index.php?project=5 )。但我想学习如何做我自己,所以我可以创造一切,我需要,我需要的方式。

I know that there are people out there creating classes for this (ie http://coreyoneil.com/portfolio/index.php?project=5). But I want to learn how to do it myself so I can create everything I need the way I need.

我读过关于位图和位图数据。我应该能够.draw的影片剪辑到一个位图,以便我可以再循环寻找冲突的像素。然而,这很奇怪和困惑处理偏移量。并且它接缝像MyBitMap.rect始终x = 0和Y = 0 ...我不能缝找到的东西原来的位置...

I've read about BitMap and BitMapData. I should be able to .draw the MovieClips onto a BitMap so I could then cycle the pixels looking for the collisions. However, It's weird and confusing dealing with the offsets.. And it seams like the MyBitMap.rect has always x = 0 and y = 0... and I can't seam to find the original position of the things...

我想首先做一个hitTestObject,那么如果这是肯定的,我将调查悫的影片剪辑矩形的像素碰撞交集。 但也有另外一个问题(影片剪辑的旋转)......

I'm thinking of doing a hitTestObject first, then if this was positive, I would investigate the intersection betwen the movieclips rectangles for the pixel collisions. But then there is also another problem (the rotation of movieclips)...

...我需要一些启示这里如何做到这一点。 请,任何帮助,将AP preciated ..

...I need some enlightment here on how to do it. Please, any help would be appreciated..

推荐答案

我设法做到这一点毕竟,我已经写了我的课碰撞检测,/碰撞角度等花絮。

I managed to do it after all, and I already wrote my class for collision detections,/collisions angle and other extras.

最令人困惑的过程也许是正确对齐的位图进行比较。当WHE平局()一个影片剪辑成AA的BitmapData,如果我们的addChild()对应的位图,我们可以看到它的一部分是不可见的。这似乎是部分远离绘制从中心向右和向下仅留下顶部和左侧从beeing绘制。该溶液是给在该对齐的位图,并使其所有绘制的绘制方法的第二个参数变换矩阵

The most confusing process is maybe to align the bitmaps correctly for comparing. When whe draw() a movieclip into a a BitmapData, if we addChild() the corresponding Bitmap we can see that part of it is not visible. it appears to be drawn from the center to right and down only, leaving the top and left parts away from beeing drawn. The solution is giving a transform matrix in the second argument of the draw method that aligns the bitmap and makes it all be drawn.

这是我班一个函数的例子创建位图进行比较:

this is an example of a function in my class to create a bitmap for comparing:

    static public function createAlignedBitmap(mc: MovieClip, mc_rect: Rectangle): BitmapData{
                var mc_offset: Matrix;
                var mc_bmd: BitmapData;

                mc_offset = mc.transform.matrix;
                mc_offset.tx = mc.x - mc_rect.x;
                mc_offset.ty = mc.y - mc_rect.y;
                mc_bmd = new BitmapData(mc_rect.width, mc_rect.height, true, 0);
                mc_bmd.draw(mc, mc_offset);

                return mc_bmd;
}

为了使用它,如果你是在时间轴上,你做的:

in order to use it, if you are on the timeline, you do:

className.createAlignedBitmap(myMovieClip, myMovieClip.getBounds(this))

注意使用的getBounds返回其在该影片剪辑被嵌入的矩形。这使得偏移矩阵的计算

Notice the use of getBounds which return the rectangle in which the movie clip is embedded. This allows the calculation of the offset matrix.

此方法非常相似,在这里显示的http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

This method is quite similar to the on shown here http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

通过的途径,如果这是一个有趣的事情给你,检查我,我会后稍等片刻,等问题。

By the ways, if this is an interesting matter for you, check my other question which I'll post in a few moments.

这篇关于ActionScript 3的像素完美碰撞。如何? (学习目的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆