橡皮怪main.js
来源:互联网 发布:法学双学位算法本吗 编辑:程序博客网 时间:2024/04/28 12:42
node:节点
节点也继承了 EventTarget,它允许节点发送事件。
Node.EventType 支持的节点事件
统一资源定位符(URL) 外部导入的东西(图片,音频等)
类型(type) cocos程序中内部的东西
type: cc.ProgressBar 进度条组件
type: cc.ParticleSystem 粒子效果
接口(interface)
类(class)
any写入一些东西
extends: cc.Component, //继承属性类
索引 属性(properties)
default其他情况 //在C中与switch配合使用
node 基本节点
node 文本绑定的地方 this.node本节点
property 定义 CCClass 所用的属性
(随意起名):cc.Label 文本组件
url: AudioClip cc库中音频资源类(一般有多个音效)
例子:
player:cc.Node, //在cocos中拖入主角
player //变量
this.player //调用主角节点
Position.x //自动获取主角位置(一般类似的都是跟主角位置有关)
Node.setPosition //设置节点在父节点坐标系中的位置。
var newDici = cc.instantiate(this.dici); //克隆新的地刺
node.addChild(newDici) //添加子节点
runAction(sque1); //执行参数中的东西
cc.instantiate(this.dici) //克隆指定的任意类型对象
cc.director.preloadScene(“over”); //预加载场景文件
cc.sequence(goR1,goR2) //按顺序执行操作
cc.random0To1() //默认0到1
cc.Prefab //预制资源类(预制件)
cc.director.loadScene(‘over’) 通过场景名称加载场景
//把分数存储到本地
this.score += 1;
cc.sys.localStorage.setItem(“score”,this.score);
//获取当前触点位置
touch.getLocation()
var locationInNode = touch.getLocation();
cc.p 通过简便的函数进行创建
var goR1= cc.moveBy(0.25,cc.p(0,200)); //0.25秒到 起点+200 的位置
var goR2= cc.moveBy(0.25,cc.p(0,-200)); //0.25秒到达起点处坐标位置
cc.Class({ extends: cc.Component, //继承属性类 properties: { _LEFT: -1, _RIGHT: 1, score:0, playTime:60, //游戏时间,倒计时 playTime:90, diciCount:0, //地刺数量 dc_duration:320, //地刺的间隔距离 dici:cc.Prefab, //地刺预制件 // dflasf:23, //自定义后property中就会包含定义的属性 //主角节点 player:cc.Node, //背景音乐 bgAudio: { default:null, url:cc.AudioClip }, //主角跳跃音效 jumpAudio: { default:null, url:cc.AudioClip //音频组件 }, //进度条 progressBar: { default: null, type: cc.ProgressBar //进度条组件 }, //粒子效果 gameParticle: { default: null, type: cc.ParticleSystem //粒子组件 }, timeLabel:cc.Label, //倒计时文本 scoreLabel:cc.Label, //得分文本 }, playerDown:function() { var action1 = cc.scaleTo(0.09,0.5,0.5); this.player.runAction(action1); }, playerUp:function() { var action1 = cc.scaleTo(0.09,1,1); this.player.runAction(action1); }, onLoad: function () { //计时器 this.schedule(this.NewDici,1); //设置音效的音量 cc.audioEngine.setEffectsVolume(0.1); cc.audioEngine.playMusic(this.bgAudio,true); //给屏幕设置点击事件,控制主角动作 this.node.on(cc.Node.EventType.TOUCH_START,this.setInputControl.bind(this),this); cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN,function(event){ switch(event.keyCode) { case 38: this.playerMove(); break; case 40: this.playerDown(); cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP,function(event){ this.playerUp(); },this); break; default: break; } },this); this.player.setPosition(-100,-296); this.timeLabel.string = "倒计时: "+this.playTime; cc.director.preloadScene("over"); //预加载场景文件 this.score=0; var time = this.playTime; //添加计时器实现场景定时切换 this.schedule(function() { var ratio = this.playTime/time; this.progressBar.progress = ratio; this.playTime--; this.timeLabel.string = "last: "+this.playTime; // if(this.playTime<=0){ // cc.audioEngine.pauseMusic(); // cc.director.loadScene('over'); // } },1); }, //得到新的地刺 NewDici:function() { this.diciCount+=1; //克隆指定的任意类型对象 var newDici = cc.instantiate(this.dici); //node.addChild(newDici)创建了一个newDici节点 this.node.addChild(newDici); //范围0到1随机 var randD = cc.random0To1(); // newDici.rotationX = (randD >= 0.5) ? 0 : 180; //newDici.setPosition()等价于node.setPostion(x,y)需要两个参数 newDici.setPosition(this.diciPosition(randD)); }, //地刺的出现位置 diciPosition:function(randD) { var randX=0; var randY=0; randX = 600; if(randD>0.5) { randY=-200; } else { randY=-260; } return cc.p(randX,randY); }, //主角跳跃逻辑 playerMove:function() { ////移动过程中暂停节点所有侦听事件 cc.eventManager.pauseTarget (this.node,true); ////////////////////// // var duration = bValue ? this._RIGHT : this._LEFT; // var _rotationY = bValue ? 0 : 0; // var goOtherSide= cc.moveTo(0.1,cc.p((this.node.width/2-80) * duration, // this.player.getPositionY())); var goR1= cc.moveBy(0.25,cc.p(0,200)); var goR2= cc.moveBy(0.25,cc.p(0,-200)); var sque= cc.sequence(goR1,goR2); /////////////////////////////////////////////////////////////// //主角动作完成时恢复节点上的触摸侦听事件 var callFunc = cc.callFunc(function() { cc.eventManager.resumeTarget(this.node,true); },this); var sque1=cc.sequence(goR1,goR2,callFunc); //cc.log(this.player.position); cc.log(this.player.position); //限定主角位置 if(this.player.position.y<-295&&this.player.position.y>-297) { this.player.runAction(sque1); } }, //设置玩家控制 setInputControl:function(touch,event) { cc.audioEngine.playEffect(this.jumpAudio,false); var locationInNode = touch.getLocation(); this.playerMove(true); //怪物移动 this.score += 1; //把分数存储到本地 cc.sys.localStorage.setItem("score",this.score); this.scoreLabel.string = "Score: " + this.score; //this.NewDici(); },});
- 橡皮怪main.js
- 橡皮怪Dici,over,welcome,player
- Node.js ,require.main
- 大鱼吃小鱼游戏-main.js
- 大鱼吃小鱼游戏-main.js
- VUE如何加载main.js
- vue入口文件main.js
- 转载:橡皮圆
- 橡皮鸭 调试法
- 橡皮族 来源:沪江
- 橡皮族 来源:沪江
- 橡皮条制作
- 橡皮鸭调试法
- vue-cli main.js文件详解
- 用橡皮破解BAD_POOL_CALLER错误
- 橡皮鸭程序调试法
- 橡皮鸭程序调试法
- 橡皮鸭程序调试法
- 算法练习(33):Minimum ASCII Delete Sum for Two Strings
- 左手用R右手Python系列之——表格数据抓取之道
- 10块钱看家8会员视频http://img.blog.csdn.net/20171222194146803
- 广告投入是怎样提高新用户数的(岭回归及主成分回归) | R语言商业分析实践3
- 学历真的改变能命运? | 数据告诉你
- 橡皮怪main.js
- github的个人博客及本地文件上传
- jzoj 1935. 【2011集训队出题】单选错位
- <algorithm>
- 不知道怎么赚取积分
- ios-信任服务器证书
- erlang 的垃圾回收机制简介
- 判别模型与生成模型的区别
- Andoird主子线程通信,子线程不能更新UI