按照官網教程寫的,發現運行以后,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) {
// },
})