最近用到过的函数

注意:
循环判断内部如果不初始化的话容易到导致判断失效
封装函数的时候生成和功能最好分开写,除非需求必要

COCOS
//通过层级管理器找到main脚本,在找到bombList预制件
var bomPrefab = cc.find(‘Canvas’).getComponent(‘Main’).bombList[0];

数字游戏

//Node是组件实例
//小写node是对象
生命周期回调
onLoad
start
update
lateUpdate
onDestroy
onEnable
onDisable


//enabled 激活的(可以用在按钮功能上) ndoe.enabled = false;
//开启物理系统
cc.director.getCollisionManager().enabled = true;
//碰撞系统回调

onCollisionEnter:function(other, self)

动画 音频:
cc.audioEngine.playEffect(this.bombAudio,false);//播放短音频

Animation 组件用于播放动画
//获取帧动画节点播放’hide’组件
node.getComponent(cc.Animation).play(‘hide’)

playAdditive //播放指定动画
var animCtrl = this.node.getComponent(cc.Animation);
animCtrl.playAdditive(“linear_1”);

animCtrl.playAdditive(“linear_2”);

cc.callFunc //执行回调函数
//查找层级获取层级管理器指定内容
cc.find(name).getComponent(‘Main’)

//储存和设置获取的项目的数据
cc.sys.localStorage.getItem(‘the_Highscore’)
cc.sys.localStorage.setItem(‘the_Highscore’,100);
this.node.getComponent(cc.Label) //获取节点组件

Node.opacity() //节点透明度
cc.fadeTo() //修改透明度到指定值
cc.moveTo() //移动到目标位置。
cc.scaleTo() //将节点大小缩放
cc.rotateBy(5,360) //角度旋转
Math.random() //随机数
Math.abs() //绝对值
toFixed(2) //保留小数两位
cc.moveBy(0.5,cc.p(1,2)); //移动指定的距离。
parseInt(Math.random()*3) //转换为int类型
node.active = false; //Boolean 当前节点的自身激活状态
this.ball.visible=true //节点显示(cocos2d-js)
cc.instantiate //克隆
getPosition() //获取坐标

setPosition() //设置坐标

setEnabled(true) //启用或禁用事件管理器true false

this.butt.setEnabled(false);//按钮的禁用

Label:
this.lab = new cc.LabelTTF(“得分:0”, “Arial”, 38);
this.score=3;
this.lab.string=”得分:”+this.score;
this.lab.color=cc.color(0,0,0);
this.lab.setPosition(400,750);

this.addChild(this.lab);

cc.spawn() //同步执行动作
cc.sequence //顺序执行
cc.repeatForever //永远重复一个动作

//在运行中如果需要在播放动画后调用函数就需要用到回调函数(计算器运行是不会等动画播放完的),因此需要用到回调函数
cc.callFunc(this.destroySocre.bind(this))
this.node.runAction(cc.sequence(spawn,cc.callFunc(this.destroySocre.bind(this))));//执行完第一个动作后,再执行第二个动作
node.runAction()//运行操作

计时器
//setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式
setTimeout(this._show.bind(this),1000);

this.schedule(function(){},1)//计时器每一秒执行一次
update:function(){} //每帧执行
this.unschedule() //取消调度一个自定义的回调函数(取消后函数将不再调用)


cc.EventListener.TOUCH_ONE_BY_ONE (单点触摸)
cc.EventListener.TOUCH_ALL_AT_ONCE (多点触摸)
cc.EventListener.KEYBOARD (键盘)
cc.EventListener.MOUSE (鼠标)
cc.EventListener.ACCELERATION (加速计)
cc.EventListener.CUSTOM (自定义)

// 设置是否吞没事件,在 onTouchBegan方法返回 true 时吞掉事件,不再向下传递。
swallowTouches: true,  
//实现 onTouchBegan 事件处理回调函数
onTouchBegan:function(touch, event)
{

    return self.checkHit(touch.getLocation());  //传递坐标
},
//实现onTouchMoved事件处理回调函数, 触摸移动时触发
onTouchMoved:function(touch, event)   //
{
    self.movePickedHitTile(touch.getLocation());
    return true;

},

 onTouchEnded:function(touch, event)// 实现onTouchEnded事件处理回调函数

{
self.dropTile(touch.getLocation());
return true;
}
});

cc.eventManager.addListener(this.touchListener, node);  // 添加监听器到管理器
event.getUserData() //获取用户数据

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值