Cocos Creator 使用 cc.tween 緩動方法報錯的問題


按照官網教程寫的,發現運行以后,F12控制台報錯:

Uncaught TypeError: cc.tween is not a function

解決辦法:

不使用 cc.tween, 換成 moveBy + runAction即可。

cc.Class({
  extends: cc.Component,

  properties: {
    // 主角跳躍高度
    jumpHeight: 0,
    // 主角跳躍持續時間
    jumpDuration: 0,
    // 最大移動速度
    maxMoveSpeed: 0,
    // 加速度
    accel: 0,
  },

  runJumpAction: function () {
    // // 跳躍上升
    // var jumpUp = cc
    //   .tween()
    //   .by(this.jumpDuration, { y: this.jumpHeight }, { easing: 'sineOut' })
    // // 下落
    // var jumpDown = cc
    //   .tween()
    //   .by(this.jumpDuration, { y: -this.jumpHeight }, { easing: 'sineIn' })

    // // 創建一個緩動,按 jumpUp、jumpDown 的順序執行動作
    // var tween = cc.tween().sequence(jumpUp, jumpDown)
    // // 不斷重復
    // return cc.tween().repeatForever(tween)

    var jumpUp = cc
      .moveBy(this.jumpDuration, cc.p(0, this.jumpHeight))
      .easing(cc.easeQuadraticActionOut())
    var jumpDown = cc
      .moveBy(this.jumpDuration, cc.p(0, -this.jumpHeight))
      .easing(cc.easeQuadraticActionIn())
    return cc.repeatForever(cc.sequence(jumpUp, jumpDown))
  },

  // use this for initialization
  onLoad: function () {
    // var jumpAction = this.runJumpAction()
    // cc.tween(this.node).then(jumpAction).start()
    this.jumpAction = this.runJumpAction()
    this.node.runAction(this.jumpAction)
  },

  // called every frame, uncomment this function to activate update callback
  // update: function (dt) {

  // },
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM