使用createjs进行碰撞检测

使用createjs进行碰撞检测

本文介绍了使用createjs进行碰撞检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是createjs的一个新手,希望了解有关冲突检测这一主题的一些指导。我已经使用循环使用了很棒的字体创建了一些文本对象。接下来,我将它们保存为变量 objx 作为 id ,同时更新其位置坐标(x, y)。这是冲突检测的代码:

I am a complete novice in createjs and wanted some guidance over this topic of collision detection. I have created some text objects using font awesome using a loop. Next I saved them in variable objx as id along with updating its position coordinates(x,y) in it. And here is the code for collision detection:

createjs.Ticker.addEventListener("tick", function(){
    var jx,jy,jt,t;
        for(var i = 0 ; i < objx.length-1 ; i++)objx[i].id.color="#8B0000";
        for(var i = 0 ; i < objx.length-1 ; i++){
            x = objx[i].x;y = objx[i].y;t = objx[i].id;
            for(var j = i+1 ; j < objx.length-1 ; j++){
                jx = objx[j].x;jy = objx[j].y;
                if(x+t.getMeasuredWidth()>=jx && y+t.getMeasuredHeight()>=jy )
                {
                    jt = objx[j].id;
                    jt.color="#0000CD";
                    t.color="#0000CD";
                }
            }
        }
        stage.update();});
  }


}

初始部分tweenjs的运行正常。我只是希望以这种方式发生碰撞,使得文本的颜色仅在碰撞时发生变化,并且应该在碰撞后恢复为初始颜色。生成的图像类似于:

The initial part of tweenjs is working fine. I just wanted the collision to occur in such a way such that color of text changes only on collision and should be back to initial color after collision. This generates an image which is similar to :

推荐答案

这对于EaselJS冲突检测非常有用。

This is very good for EaselJS collision detection.Collision Detection

您可以使用像素完美检测或边界框碰撞检测。

You could use either pixel perfect detection or The bounding box collision detection.

这篇关于使用createjs进行碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:34