Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated scaling discrepancies with openfl-disable-graphics-upscaling flag #2165

Open
Continuities opened this issue Apr 11, 2019 · 1 comment

Comments

@Continuities
Copy link

Continuities commented Apr 11, 2019

Animated scaling of vector shapes behaves very differently when the openfl-disable-graphics-upscaling is set.

This code draws a circle and animates its scale:

package;

import openfl.display.Shape;
import openfl.display.Sprite;
import openfl.display.StageScaleMode;
import motion.Actuate;
import motion.easing.Linear;

class Main extends Sprite {

  private static inline var CACHE_AS_BITMAP = true;
  private static inline var START_AT_ZERO = true;
  private static inline var USE_AS_MASK = false;

  private static inline var WIDTH = 500;
  private static inline var HEIGHT = 500;

  public function new() {
    super();

    stage.scaleMode = StageScaleMode.NO_SCALE;

    graphics.beginFill(0x0000ff);
    graphics.drawRect(0, 0, WIDTH, HEIGHT);
    graphics.endFill();

    var circle = new Shape();
    circle.graphics.beginFill(0xff0000);
    circle.graphics.drawCircle(0, 0, 100);
    circle.graphics.endFill();
    circle.scaleX = circle.scaleY = 1;
    circle.cacheAsBitmap = CACHE_AS_BITMAP;
    
    addChild(circle);
    circle.x = WIDTH / 2;
    circle.y = HEIGHT / 2;

    if (USE_AS_MASK) {
      this.mask = circle;
    }

    Actuate
      .update(
        val -> circle.scaleX = circle.scaleY = val, 
        1, 
        [ START_AT_ZERO ? 0 : 0.1 ], 
        [ 1 ]
      )
      .ease(Linear.easeNone);
    
  }
}

Without the openfl-disable-graphics-upscaling flag, it behaves as expected for all values of the constants CACHE_AS_BITMAP, START_AT_ZERO, and USE_AS_MASK: normal

Set openfl-disable-graphics-upscaling, though, and things get weird. Different values of CACHE_AS_BITMAP, START_AT_ZERO, and USE_AS_MASK generate very different results.

With START_AT_ZERO = true, nothing ever renders. I expect this is because the bitmap is generated with scale of 0, despite having set scaleX and scaleY to 1 earlier:
zero

With START_AT_ZERO = false and CACHE_AS_BITMAP = true, the circle is cached with scale 0.1 and scaled up from there. This is alright, but I would expect the cached bitmap to be of the initial scale of 1:
cached

With START_AT_ZERO = false and CACHE_AS_BITMAP = false, scaling doesn't work at all. Instead, we get translation of the circle scaled to 0.1:
noncached

Further, with USE_AS_MASK = true then we always get the translation behaviour, regardless of the CACHE_AS_BITMAP value:
mask

@Continuities
Copy link
Author

Any information on this at all? It's blocking me from implementing some optimizations that I need for release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant