cocos js api的一些好用的方法

<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-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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值