Cocos Creator 实现摩天轮效果

这篇博客详细介绍了如何使用Cocos Creator实现摩天轮的旋转效果,包括设置半径、圆心、预制体间隔角度等参数,并通过触摸事件控制摩天轮的旋转速度和惯性,同时包含旋转的阻力计算和回转调整策略。
摘要由CSDN通过智能技术生成
第一次写博客 导致紧张吓得我直接贴代码
cc.Class({
    extends: cc.Component,

    properties: {
        selecNode: {
            default: null,
            type: cc.Node
        },
        item: {
            default: null,
            type: cc.Prefab
        },
        radius: 0,  //半径
        pCenter: cc.Vec2, //圆心
        angleInterval: 0, //每个预制体之间的间隔角度
        angleFx: 0, //阻力系数
        speedMin: 0.1, //最小转速
        itemNum: 0, //预制体个数
        //滑动的最终角度,用来设置最小角度和最大角度
        angleMin: 0,
        angleMax: 0,
        beginVec: cc.Vec2,
        touchVec: cc.Vec2,
        backNum: 0,
        oldVec: 0,//记录上一次角度的位置
        beginPoint: cc.Vec2, //开始的位置
        movePoint: cc.Vec2,
        guanxing: cc.repeatForever,
        count: cc.repeatForever,
        angleDx: null,
        angleS: 0,
        time: 0,
        angleSpeed: 0,
        stopTime: 0,
        angleDx_Save: null,
        direction: 0,
        beRotation: 0,
        Speed: 0,
        i: 0

    },

    // use this for initialization
    onLoad: function () {
        this.initSelecScene();

    },
    buttonEvent: function (event, data) {
        if (data === 'back') {
            cc.director.loadScene('MainScene');
        }
    },
    initSelecScene: function () {
        this.initData();
        this.loadUI();
        this.loadTouchStartEvent();
        this.loadTouchEndEvent();
        this.loadTouchMoveEvent();
        this.updateItemAngle();
    },
    initData: function () {
        this.selecNode.rotation = 47;
        this.radius = 1600;
        this.pCenter = cc.v2(this.radius, this.radius);
        this.angleInterval = 6;
        this.angleFx = 1 / 6;
        this.speedMin = 0.1;
        this.itemNum = 6;
        this.angleMin = 47;
        this.angleMax = -2;
        this.backNum = 3;
        this.Speed = 1.9;
    },
    loadUI: function () {
        for (var i = 0; i < this.itemNum; ++i) 
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值