CocosCreator缓动系统使用---停止repeatForever命令

 

cc.tween的缓动系统使用repeatForever时会永久生效,如果有需求要让该动作在某一刻换个动作或者停下来,直接对该节点做cc.tween的修改是无效的

因此需要先将该动作停下来,以下代码会生效。

另外不能使用const nodeTween =  cc.tween(targetNode)这种方式,尝试后发现无法停止,原因推测可能是因为无法对应到该缓动系统。

cc.Tween.stopAllByTarget(targetNode);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Creator数钱小游戏源码CountMoney.zip // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { nodeMoney: cc.Node, nodeGuide: cc.Node, nodeStart: cc.Node, txtCount: cc.Label, txtTime: cc.Label, nodeMoneyBg: cc.Node, nodeTimerBg: cc.Node, nodeSpillMoney: cc.Node, txtTotal: cc.Label, }, // LIFE-CYCLE CALLBACKS: onLoad () { this.node.on(cc.Node.EventType.TOUCH_START, event => { this.onTouchStart(event); }); this.node.on(cc.Node.EventType.TOUCH_MOVE, event => { this.onTouchMove(event); }); this.node.on(cc.Node.EventType.TOUCH_END, event => { this.onTouchEnd(event); }); this.nodeMoneyBg.zIndex = 10; this.nodeTimerBg.zIndex = 10; this.nodeStart.zIndex = 20; this._touchNode = null; this._count = 0; this._isPlaying = false; }, start () { }, startGame(){ this._isPlaying = true; this.nodeStart.active = false; this.txtTime.string = 10; this.txtCount.string = 0; this._count = 0; this.startTimer(); this.spillMoney(); }, startTimer(){ this.schedule(this.timeCallback, 1); }, timeCallback(){ let time = parseInt(this.txtTime.string); time--; this.txtTime.string = time; if(time this._touchNode.y){ this._touchNode.y = pos.y; } }, onTouchEnd(event){ if(!this._isPlaying){ return; } let now = event.getLocation(); let start = event.getStartLocation(); if(now.y - start.y > 10){ let seq = cc.sequence( cc.spawn( cc.moveBy(0.3, 0, cc.winSize.height), cc.scaleTo(0.3, 0.7) ), cc.removeSelf(), ); this._touchNode.runAction(seq); } this._count++; this.txtCount.string = `${this._count * 100}`; }, onClick(){ this.startGame(); }, spillMoney(){ let seq = cc.sequence( cc.delayTime(0.2), cc.callFunc( () => { let x = Math.random() * cc.winSize.width; x -= cc.winSize.width / 2; let node = cc.instantiate(this.nodeSpillMoney); node.active = true; node.parent = this.nodeSpillMoney.parent; node.runAction(cc.sequence( cc.place(x, cc.winSize.height / 2 + node.height / 2), cc.spawn(cc.moveBy(1, 0, -cc.winSize.height - node.height / 2), cc.rotateBy(1, 1080)), cc.removeSelf(), )); }), ); seq.setTag(0xff); this.node.runAction(seq.repeatForever()); }, });
Creator口红机实现lipstick_3.zip // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html var DataMgr = require('DataMgr'); var LayerMgr = require('LayerMgr'); cc.Class({ extends: cc.Component, properties: { nodePlate: cc.Node, // 板子 nodeTouch: cc.Node, // 触摸节点 nodeLipstick: cc.Node, // 口红位置 prefabLipstick: cc.Prefab, // 口红预制 nodeLipstickContainer: cc.Node, // 总共有多少口红容器 }, // LIFE-CYCLE CALLBACKS: onLoad () { let mgr = cc.director.getCollisionManager(); mgr.enabled = true; // mgr.enabledDebugDraw = true; // mgr.enabledDrawBoundingBox = true; }, start () { this.nodeTouch.getComponent('Touch').setCallback( () => { this.onTouchCallback(); }); this.reloadUI(); this.startRun(); }, // update (dt) {}, startRun(){ // 顺时针转一圈,再逆时针转一圈,如此反复 this.nodePlate.stopAllActions(); this.nodePlate.rotation = 0; let seq = cc.sequence( cc.rotateBy(4, 360).easing(cc.easeIn(1.5)), cc.rotateBy(4, -360).easing(cc.easeIn(1.5)), ); this.nodePlate.runAction(seq.repeatForever()); }, /** * @description: 点击屏幕回调 * @param {type} * @return: */ onTouchCallback(){ // 口红用完了 if(DataMgr.leftLipstick <= 0){

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值