weixin_39939668 2020-11-29 22:10
浏览 0

[bug?] Component onUpdate methods not always being fired.

This has happened in several times to me already, with versions of Famous Engine ranging from 0.5 to 0.7.2, but I'm not at all sure what I have to do prior in order to experience the problem. I have some code like this:

 js
    ...
    this._positionTransitionable = new Transitionable(0)
    this._positionTransitionable.set(200, {duration: 600, curve: 'easeOut'})
    let self = this
    console.log('node?', node) // node exists, and is a Node
    self._goForwardAnimation = node.addComponent({
        onUpdate() {
            console.log('animating forward') // never fires
            if (self._positionTransitionable.isActive()) {
                let position = node.getPosition()
                node.setPosition(position[0], position[1], self._positionTransitionable.get())
                node.requestUpdateOnNextTick(self._goForwardAnimation)
            }
            else { // clean up.
                console.log('Getting rid of the component.')
                node.removeComponent(self._goForwardAnimation)
            }
        }
    })
    node.requestUpdateOnNextTick(self._goForwardAnimation)
    ...

The expected behavior is that the _goForwardAnimation will start updating after being started with node.requestUpdateOnNextTick, but it doesn't happen. The console.log inside the component never fires.

该提问来源于开源项目:Famous/engine

  • 写回答

6条回答 默认 最新

  • weixin_39939668 2020-11-29 22:10
    关注

    I ran into this again. This time I can change a single number (the duration of an animation) to get different reproducible results. I have code like this:

     js
            let thisCardNode = this.getFamousNode()
            let cardNodes = getAllChildCardNodes(thisCardNode)
            console.log(cardNodes)
            this._positionTransitionable = new Transitionable(0)
            this._positionTransitionable.set(1.0, {duration: 600, curve: 'easeOut'})
            let targetTransparency = 0.5
            let targetPosition = 200
            let self = this
            for (let i=0, len=cardNodes.length; i<len i console.log up forward animation. let cardnode="cardNodes[i]" cardnode._goforwardanimation="cardNode.addComponent({" onupdate if position="cardNode.getPosition()" cardnode.setposition self._positiontransitionable.get cardnode.requestupdateonnexttick else clean rid of the component. cardnode.removecomponent></len>

    That results (after the animation is complete) in something that looks like this:

    screenshot from 2015-08-22 21-37-32

    What you see in the image is that that only the green card has moved forward in 3D space, while cards below it (blue and yellow) have not. The expected behavior is that the green card and it's blue and yellow children all move forward.

    Now, if I change the duration of the animation from 75 to 600, the result is that now the green and yellow cards move forward, but not the blue cards (this behavior is consistent when the duration is 600):

    screenshot from 2015-08-22 21-41-47

    You can see the yellow cards are bigger now since they are closer to the camera.

    If I switch back to a duration of 75, the result is precisely the same: only the green card moves forward.

    I could place all the cards in a single node, and animate just that single node, but that hasn't been working out for me either (probably the same problem, I just haven't found the magic number that makes it work).

    评论

报告相同问题?