var o0 = require('o0'); var o0CC = require('o0CC'); var o0Game = require('o0Game'); cc.Class({ extends: cc.CircleCollider, properties: { //bodyParentNode: null, gameScene: null, head:null, body:[cc.Node], size:40,//大小,直径 //bodySize: this.radius 子类CircleCollider的变量 score: 0, color:null, bodyLength: { get: function (){ return this.score / Math.pow(this.body[0].scaleX * this.body[0].scaleY,1.5); } }, skin:null, nameLabel:null, }, setScore:function(score){ this.score = score; this.updateScale(); var targetBodyLength = Math.ceil(this.bodyLength); while(targetBodyLength > this.body.length){ this.addBody(); } while(targetBodyLength < this.body.length && this.body.length > 1){ this.removeBody(); } }, updateScale:function(){ var newScale = Math.pow(1+(this.score - 10)/50,1.0/3); for(var i=0;i1;){ this.removeBody(); } }, // use this for initialization onLoad: function () { this.radius = 20;//圆碰撞体的局部变量 this.color = o0CC.randomBrightColor(); this.addHead(); //cc.log('snake log'); }, start: function () { var sprite = o0CC.addScriptNode(this.head,cc.Sprite,1); //var sprite = this.head.addComponent(cc.Sprite,0); sprite.trim = true; sprite.type = cc.Sprite.Type.SLICED; sprite.sizeMode = cc.Sprite.SizeMode.CUSTOM; sprite.SrcBlendFactor = cc.macro.BlendFactor.SRC_ALPHA; sprite.DstBlendFactor = cc.macro.BlendFactor.ONE_MINUS_SRC_ALPHA; sprite.node.width = this.size; sprite.node.height = this.size; //var sprite = this.body[0].getComponent(cc.Sprite); cc.loader.loadRes('snake/'+this.skin[0], cc.SpriteFrame, function (err, spriteFrame) { sprite.spriteFrame = spriteFrame; }); }, lateUpdate:function(){ if(this.nameLabel!=null){ if(this.nameLabel.string==null||this.nameLabel.string==''){ this.nameLabel.string = this.name+'\n\n';/** */ } this.nameLabel.node.rotation = -this.head.rotation; } }, /* // called every frame update: function (dt) { }, onCollisionEnter:function(other,self){ }, onCollisionExit:function(other,self){ },/** */ _onPreDestroy:function(){ //cc.log('dsada'); /* while(this.body.length > 1){ this.removeBody(); }/** */ },/* test:function(){ cc.log('snake'); },/** */ }); //module.exports = Snake;