collision detection using createjs

南笙酒味 提交于 2019-12-12 03:08:20

问题


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();});
  }


}

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 :


回答1:


This is very good for EaselJS collision detection. Collision Detection

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



来源:https://stackoverflow.com/questions/28950618/collision-detection-using-createjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!