Cocos2d js 实现转盘抽奖

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">下面实现旋转的主要逻辑。主要逻辑就是,当玩家拨动旋转的箭头,给它一个初速度,接下来就有 一个由于空气的摩擦力导致的反向加速度,使得速度不断地降低,直到为0,这时,箭头停在哪个位置,就得到哪个位置的奖品,玩家力度的大小决定初速度的大小。</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">
</span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"></span><pre name="code" class="javascript">var VISIBLE_WIDTH = 960;//宽
var VISIBLE_HEIGHT = 640;//高

var Roulette = cc.LayerColor.extend({
    angle:null,//旋转的角度
    a:null,//加速度
    v:null,//旋转的初速度

    init:function(color,width,height){
        var bRet = false;
        do{
            if(!this._super(color,width,height)) break;
            cc.log("what...");
            bRet = true;

            var director = cc.Director.getInstance();
            var size = director.getWinSize();

            //轮盘
            this.background = cc.Sprite.create("res/editor_ui/editAction/tbg.png");
            this.addChild(this.background);
            this.background.setAnchorPoint(0.5,0.5);
            this.background.setPosition(cc.p(size.width/2,size.height/2));

            //箭头
            this.pointer = cc.Sprite.create("res/editor_ui/editAction/arrow.png");
            this.pointer.setAnchorPoint(0.5,0);
            //this.pointer.setPosition(cc.p(this.background.width/2,this.background.height/2));
            this.pointer.setPosition(cc.p(204,215));

            this.background.addChild(this.pointer,1);

            this.setTouchMode(cc.TOUCH_ONE_BY_ONE);
            this.setTouchEnabled(true);

            this.angle = 0;
            this.v = 20;
            this.a = 0.05;//5度
            this.scheduleUpdate();

            //cc.registerTargetedDelegate(-999,false,this);

        }while(0);
        return bRet;
    },

    onTouchBegan:function(touch, event){
        cc.log("began");
        this.startPosition = touch.getLocation();
        return true;
    },

    onTouchMoved:function(touch, event){
        cc.log("moved");
        return true;
    },

    onTouchEnded:function(touch, event){
        cc.log("end");
        var pos = touch.getLocation();
        this.endPosition = touch.getLocation();

    },

    update:function(dt){
        this.v += this.a;
        if(this.v < 0)
        {
            this.v = 0;
        }
        this.angle += this.v;
        if(this.v > 0){
            this.pointer.setRotation(this.angle);
        }
        else{
            this.unscheduleUpdate();
        }
    }

});



Roulette.create = function () {
    var main = new Roulette();
    if(main && main.init(cc.c4b(255,255,255,255),960,640)) {
        return main;
    }
    return null;
};

Roulette.scene = function(){
    var scene = cc.Scene.create();
    var layer = Roulette.create();
    scene.addChild(layer, 1);
    return scene;
};
/**
 * Created by Administrator on 2014/8/29.
 */



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值