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) {
// },
})
posted @ 2020-12-30 16:09  Function-Fun  阅读(2218)  评论(0)    收藏  举报
编辑推荐:
· 为什么PostgreSQL不自动缓存执行计划?
· 于是转身独立开发者
· C#.Net筑基-泛型T & 协变逆变
· dotnet 代码调试方法
· DbContext是如何识别出实体集合的
阅读排行:
· 【Cursor保姆级教程】零基础小白从安装到实战,手把手教你玩转AI编程神器!
· Cursor 实战万字经验分享,与 AI 编码的深度思考
· MySQL查询执行顺序:一张图看懂SQL是如何工作的
· 用 AI 制作超长视频,保姆级教程!
· GIM 1.5发布了! 支持Windows系统了
点击右上角即可分享
微信分享提示