cocosCreate 黄金矿工绳索摆动,以及钩子的扔出和回收

这篇博客详细介绍了如何在cocosCreate中实现黄金矿工游戏中的绳索摆动效果。通过记录起始位置,使用cc.rotateTo创建摇摆动作,并设置绳子的回收动作,使绳子在收回后继续摇摆。同时,通过监听触摸事件来控制钩子的扔出和回收,动态计算绳子伸长的动作,实现了游戏中的交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

this.startPos = this.rope.position;  //记录起始位置

//绳子摇摆动作
this.shakeAction = cc.repeatForever(cc.sequence(cc.rotateTo(3,60),cc.rotateTo(3,-60)));   // 回收钩子
//绳子收回动作,绳子收回后执行摇摆动作

this.returnAction = cc.sequence(cc.moveTo(3,this.startPos),cc.callFunc(function() {

    self.rope.getComponent(cc.Animation).resume('shake');   // 继续摇摆
}, this));

//绳子左右摇摆
this.rope.runAction(this.shakeAction);

var self = this;
this.node.on('touchstart',function(){




    self.rope.getComponent(cc.Animation).pause('shake');  //  将摆动暂停
    self.rope.stopAllActions();
    //绳子伸长动作,根据角度动态计算
  //  var move1  = cc.moveBy(3,cc.p(-200*Math.tan(Math.PI/180*this.rope.rotation),-200))
  //  self.rope.runAction(cc.sequence(move1, cc.callFunc(this._callFun, this)));


    self.rope.runAction(cc.moveBy(2,-300*Math.tan(Math.PI/180*this.rope.rotation),-300));  //钩子扔出
},this);
this.node.on('touchend',function(){


    self.rope.runAction(self.returnAction);

},this);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值