使用3.3.0 开发 官方教程 怪物吃星星 游戏 求教

其中关于tween 动画的官方教程编写如下:

` // 跳跃上升
    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);`

我在3.3.0上的使用TS编写后,没有报错,但是没有动画效果。我写的代码如下:
`
private runJumpAction(){

    log("跳跃的高度"+this.jumpHeight);

    var jumpUp = tween().by(this.jumpDuration,{y:this.jumpHeight},{easing:"sineOut"})

    var jupmDown = tween().by(this.jumpDuration,{y:-this.jumpHeight},{easing:"sineIn"})

    var action = tween().sequence(jumpUp,jupmDown)

    return tween().repeatForever(action);

}

onLoad(){
var action = this.runJumpAction();
log(this.node.name);
tween(this.node).then(action).start();

}

`

我还是一个新人,不知道怎么写代码部分,帖子有点儿丑陋。还请见谅,如果有相关的教程啥的,希望能告知。

别再3.3折腾,去2.x

因为我想要在未来,在游戏中可以添加3D元素。所以才会想要从3.X开始

放在onenable里面试试

试过了,还是不可以

也许是访问不到this.node的y属性有关,换成对position进行变化试试看

太厉害了,大佬。你说的对。我把代码换成如下的形式,他可以垂直弹跳了
private runJumpAction(){

    log("持续时间:"+this.jumpDuration)

    var jumpUp = tween(this.node).by(this.jumpDuration,{position:new Vec3(0,this.jumpHeight,0)},{easing:"sineOut"})

    var jupmDown = tween().by(this.jumpDuration,{position:new Vec3(0,-this.jumpHeight,0)},{easing:"sineIn"})

    var action = tween().sequence(jumpUp,jupmDown)

    return tween().repeatForever(action);

}

客气了。我也是新手。

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。