_renderBubble (target) {
        const bubbleState = this._getBubbleState(target);
        const {drawableVisible, type, text, onSpriteRight} = bubbleState;

        // Remove the bubble if target is not visible, or text is being set to blank
        // without being initialized. See comment below about blank text optimization.
        if (!target.visible || (text === '' && !bubbleState.skinId)) {
            return this._onTargetWillExit(target);
        }

        if (bubbleState.skinId) {
            // Optimization: if text is set to blank, hide the drawable instead of
            // getting rid of it. This prevents flickering in "typewriter" projects
            if ((text === '' && drawableVisible) || (text !== '' && !drawableVisible)) {
                bubbleState.drawableVisible = text !== '';
                this.runtime.renderer.updateDrawableProperties(bubbleState.drawableId, {
                    visible: bubbleState.drawableVisible
                });
            }
            if (bubbleState.drawableVisible) {
                this.runtime.renderer.updateTextSkin(bubbleState.skinId, type, text, onSpriteRight, [0, 0]);
            }
        } else {
            target.addListener(RenderedTarget.EVENT_TARGET_MOVED, this._onTargetMoved);

            // TODO is there a way to figure out before rendering whether to default left or right?
            const targetBounds = target.getBounds();
            const stageBounds = this.runtime.getTargetForStage().getBounds();
            if (targetBounds.right + 170 > stageBounds.right) {
                bubbleState.onSpriteRight = false;
            }

            bubbleState.drawableId = this.runtime.renderer.createDrawable();
            bubbleState.skinId = this.runtime.renderer.createTextSkin(type, text, bubbleState.onSpriteRight, [0, 0]);

            this.runtime.renderer.setDrawableOrder(bubbleState.drawableId, Infinity);
            this.runtime.renderer.updateDrawableProperties(bubbleState.drawableId, {
                skinId: bubbleState.skinId
            });
        }

        this._positionBubble(target);
    }
/**
     * Create a visible bubble for a target. If a bubble exists for the target,
     * just set it to visible and update the type/text. Otherwise create a new
     * bubble and update the relevant custom state.
     * @param {!Target} target Target who needs a bubble.
     * @return {undefined} Early return if text is empty string.
     * @private
     */
Create a visible bubble for a target. If a bubble exists for the target,
just set it to visible and update the type/text. Otherwise create a new
bubble and update the relevant custom state.
@param {!Target} target Target who needs a bubble.
@return {undefined} Early return if text is empty string.
@private
Create a visible bubble for a target . If a bubble exists for the target just set it to visible and update the type / text . Otherwise create a new bubble and update the relevant custom state . @param { !Target } target Target who needs a bubble . @return { undefined } Early return if text is empty string . @private
_renderBubble (target) {
        const bubbleState = this._getBubbleState(target);
        const {drawableVisible, type, text, onSpriteRight} = bubbleState;
        if (!target.visible || (text === '' && !bubbleState.skinId)) {
            return this._onTargetWillExit(target);
        }
        if (bubbleState.skinId) {
            if ((text === '' && drawableVisible) || (text !== '' && !drawableVisible)) {
                bubbleState.drawableVisible = text !== '';
                this.runtime.renderer.updateDrawableProperties(bubbleState.drawableId, {
                    visible: bubbleState.drawableVisible
                });
            }
            if (bubbleState.drawableVisible) {
                this.runtime.renderer.updateTextSkin(bubbleState.skinId, type, text, onSpriteRight, [0, 0]);
            }
        } else {
            target.addListener(RenderedTarget.EVENT_TARGET_MOVED, this._onTargetMoved);
            const targetBounds = target.getBounds();
            const stageBounds = this.runtime.getTargetForStage().getBounds();
            if (targetBounds.right + 170 > stageBounds.right) {
                bubbleState.onSpriteRight = false;
            }
            bubbleState.drawableId = this.runtime.renderer.createDrawable();
            bubbleState.skinId = this.runtime.renderer.createTextSkin(type, text, bubbleState.onSpriteRight, [0, 0]);
            this.runtime.renderer.setDrawableOrder(bubbleState.drawableId, Infinity);
            this.runtime.renderer.updateDrawableProperties(bubbleState.drawableId, {
                skinId: bubbleState.skinId
            });
        }
        this._positionBubble(target);
    }
_renderBubble ( target ) { const bubbleState = this . _getBubbleState ( target ) ; const { drawableVisible , type , text , onSpriteRight } = bubbleState ; if ( ! target . visible || ( text === '' && ! bubbleState . skinId ) ) { return this . _onTargetWillExit ( target ) ; } if ( bubbleState . skinId ) { if ( ( text === '' && drawableVisible ) || ( text !== '' && ! drawableVisible ) ) { bubbleState . drawableVisible = text !== '' ; this . runtime . renderer . updateDrawableProperties ( bubbleState . drawableId , { visible : bubbleState . drawableVisible } ) ; } if ( bubbleState . drawableVisible ) { this . runtime . renderer . updateTextSkin ( bubbleState . skinId , type , text , onSpriteRight , [ 0 , 0 ] ) ; } } else { target . addListener ( RenderedTarget . EVENT_TARGET_MOVED , this . _onTargetMoved ) ; const targetBounds = target . getBounds ( ) ; const stageBounds = this . runtime . getTargetForStage ( ) . getBounds ( ) ; if ( targetBounds . right + 170 > stageBounds . right ) { bubbleState . onSpriteRight = false ; } bubbleState . drawableId = this . runtime . renderer . createDrawable ( ) ; bubbleState . skinId = this . runtime . renderer . createTextSkin ( type , text , bubbleState . onSpriteRight , [ 0 , 0 ] ) ; this . runtime . renderer . setDrawableOrder ( bubbleState . drawableId , Infinity ) ; this . runtime . renderer . updateDrawableProperties ( bubbleState . drawableId , { skinId : bubbleState . skinId } ) ; } this . _positionBubble ( target ) ; }
Create a visible bubble for a target.
Create a visible bubble for a target .
// Remove the bubble if target is not visible, or text is being set to blank // without being initialized. See comment below about blank text optimization. // Optimization: if text is set to blank, hide the drawable instead of // getting rid of it. This prevents flickering in "typewriter" projects // TODO is there a way to figure out before rendering whether to default left or right?