在做一个demo,代码如下:
`onLoad ( ) {
this.heroConfig = gameConfig.heroConfig
this.canvas = cc.find( 'Canvas' )
this.heroPicNode = this.node.getChildByName( 'heroPic' )
this.heroShadowNode = this.node.getChildByName( 'heroShadow' )
this.canvas.on( 'touchstart', this.shoot, this )
},
shoot( ){
let jumpTime = this.heroConfig.speedJump/this.heroConfig.gravity
let enlarge = 1 + this.heroConfig.speedJump*this.heroConfig.speedToScale
let narrow = 1/enlarge
let deltY = 2*jumpTime*this.heroConfig.speedGo
let goAction = cc.moveBy( 2*jumpTime, 0, deltY )
let jumpAction = cc.scaleTo( jumpTime, enlarge, enlarge )
let narrowAction = cc.scaleTo( jumpTime, narrow, narrow )
let fallAction = cc.scaleTo( jumpTime, 1, 1 )
this.heroShadowNode.runAction( cc.spawn(goAction, cc.sequence( narrowAction , fallAction ) ) )
this.heroPicNode.runAction( cc.spawn(goAction, cc.sequence( jumpAction, fallAction ) ) )
},`
这里为什么定义goAction,之后heroPicNode调用runAction发现heroShadowNode只能放大缩小不能向前移动,将
this.heroPicNode.runAction( cc.spawn(goAction, cc.sequence( jumpAction, fallAction ) ) )改为this.heroPicNode.runAction( cc.spawn(cc.moveBy( 2*jumpTime, 0, deltY ), cc.sequence( jumpAction, fallAction ) ) )之后正常了,这是怎么回事?
如果两个节点运动方式相同,使用定义的同一个action很正常啊,这里是因为heroShadowNode调用runAction后goAction修改了goAction对象吗?文档里有:你不应该修改 runAction 后的动作,将无法发挥作用,如果想进行修改,请在定义 action 时加入。是这个原因吗