您的位置:首页 > 移动开发 > Cocos引擎

cocos js api的一些好用的方法

2016-10-12 10:10 323 查看
<span style="font-size:18px;">1.拖尾效果,和运动轨迹为圆的方法!</span>
onEnter:function () {
this._super();

// ask director the the window size
var size = cc.director.getWinSize();
this._streak = new cc.MotionStreak(2.0, 1.0, 50.0, cc.color(255, 255, 0), s_image_icon);
this.addChild(this._streak);

this._center = cc.p(size.width / 2, size.height / 2);
this._radius = size.width / 3;
this._angle = 0.0;
this.schedule(this.update, 0);
},

update:function (dt) {
this._angle += 1.0;
this._streak.x = this._center.x + Math.cos(this._angle / 180 * Math.PI) * this._radius;
this._streak.y = this._center.y + Math.sin(this._angle / 180 * Math.PI) * this._radius;
}
<p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">1、cc.rectIntersectsRect(ra,rb) 判断两个矩形是否相交,若相交,返回true</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">用例:</p><p style="margin-top: 8px; margin-bottom: 8px; padding
a303
-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">var rectA = cc.rect(0,0,5,10);</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">var rectB = cc.rect(4,9,5,10);</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">var r = cc.rectIntersectsRect(rectA, rectB);</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">if(!r) throw "Fail rectIntersectsRect 1”;</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">2、cc.rectContainsPoint(rect,point) 判断某个矩形中是否包含某个点,若包含,返回true</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">3、cc.pointEqualToPoint(point1,point2) 判断两个点是否相等,相等返回true</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">4、cc.rectEqualToRect(rect1,rect2)判断两个矩形是否相等</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">5、cc._rectEqualToZero(rect)判断该矩形是否为0矩阵</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">6、cc.rectOverlapsRect(rectA,rectB)判断两个矩形是否部分重叠</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">7、cc.rectIntersection(rectA,rectB)返回两个矩形重叠部分</p><p style="margin-top: 8px; margin-bottom: 8px; padding-top: 0px; padding-bottom: 0px; color: rgb(55, 55, 55); font-stretch: normal; font-size: 14px; font-family: "Open Sans", sans-serif; line-height: 2em; background-color: rgb(245, 248, 253);">8、cc.rectUnion(rectA,rectB)返回包含这两个矩形的最小矩形</p>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: