hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

Caching? #99

Closed CloudyWL closed 11 years ago

CloudyWL commented 11 years ago

If I call cacheAsBitmap with a empty text field I get SCRIPT5022: DOM Exception: INVALID_STATE_ERR (11) caat.js, line 22026 character 13 It isn't consistent, but removing the noworkyActor.cacheAsBitmap seems to clear it up. The nest container may or my no be relevant. Is there any guidelines to using the cacheAsBitmap?

        var director = new CAAT.Director().initialize(
                100, 100,
                document.getElementById('canvas'));
        var scene = director.createScene();
        var container = new CAAT.ActorContainer().
            setLocation(10,10);
        workyActor = new CAAT.TextActor().
            setTextFillStyle("FFFFFF").
            setText("worky");
        container.addChild(workyActor);
        noworkyActor = new CAAT.TextActor().
            setLocation(0,30).
            setText("").
            setTextFillStyle("FFFFFF");
        noworkyActor.cacheAsBitmap();
        container.addChild(noworkyActor);
        scene.addChild(container);

        director.loop(1);
hyperandroid commented 11 years ago

that's because the textfield has no dimension and it'll end up trying to build a 0 by 0 image. i will add some code checking to avoid this situation. thanks for spotting. best

If I call cacheAsBitmap with a empty text field I get SCRIPT5022: DOM Exception: INVALID_STATE_ERR (11) caat.js, line 22026 character 13 It isn't consistent, but removing the noworkyActor.cacheAsBitmap seems to clear it up. The nest container may or my no be relevant. Is there any guidelines to using the cacheAsBitmap?

    var director = new CAAT.Director().initialize(
            100, 100,
            document.getElementById('canvas'));
    var scene = director.createScene();
    var container = new CAAT.ActorContainer().
        setLocation(10,10);
    workyActor = new CAAT.TextActor().
        setTextFillStyle("FFFFFF").
        setText("worky");
    container.addChild(workyActor);
    noworkyActor = new CAAT.TextActor().
        setLocation(0,30).
        setText("").
        setTextFillStyle("FFFFFF");
    noworkyActor.cacheAsBitmap();
    container.addChild(noworkyActor);
    scene.addChild(container);

    director.loop(1);

— Reply to this email directly or view it on GitHubhttps://github.com/hyperandroid/CAAT/issues/99.

CloudyWL commented 11 years ago

Be aware that setText resets the size on an empty string, so setting the size doesn't work around the problem. setText : function( sText ) { this.stopCacheAsBitmap(); this.text= sText; if ( null===this.text || this.text==="" ) { this.width= this.height= 0; } this.calcTextSize( CAAT.currentDirector );

        this.invalidate();

        return this;
hyperandroid commented 11 years ago

I've fixed cacheAsBitmap method instead of setText.

Thus, no matter what actor has invalid dimension for caching since it won't be cached.

It is fixed in the current released version.

Thanks.

Be aware that setText resets the size on an empty string, so setting the size doesn't work around the problem. setText : function( sText ) { this.stopCacheAsBitmap(); this.text= sText; if ( null===this.text || this.text==="" ) { this.width= this.height= 0; } this.calcTextSize( CAAT.currentDirector );

    this.invalidate();

    return this;

— Reply to this email directly or view it on GitHubhttps://github.com/hyperandroid/CAAT/issues/99#issuecomment-10686349.