<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.
*/