Hi,
I hope that you all stay safe in this corona virus dark times.
I have a project that requires to use a good number of SVG’s in a board (Sprite or bitmap), and I want to make a zoom in and a zoom out effect using actuate. I’ve manage to do that fairly easy, but when I have more than 20 SVG’s item on the board, the animation starts to look a little jerky, if I use more than 50 SVG’s then it’s not an animation any more.
This happens to the HTML5 and NEKO targets (not tried the others), but not with the FLASH target as expected. I was expecting this to happen, because I know that SVG performance degrades when the number is high, so I’ve tried using BitmapData and the performance was good even with hundreds of items, but this project require that the items look good when scaling, and they do not look good with Bitmap, even if I rescale them before putting them in the bitmap, using the smoothing options didnt help, I’ve tried the allow-high-dpi=“true”, everything I could find to make the bitmap look reasonable, and noting worked.
But one thing that is strange is when I use the HTML5 target, with the SVG (not the bitmap), the animation when scaling look jerky and slow, but if I use the browser develop tools -> “responsive design mode”, I can resize the canvas all I want and the scaling is fast with no degradation of the items. I can use 500 SVG’s and the actuate takes a minute or so to draw to the final scale, but if I rescale using the “responsive design mode” handle, it scale almost instantly.
Can someone explain to me what is in play, behind the scenes, when the browser fires an “Event.RESIZE” and openfl auto-resize the stage? How is the scaling done?
I’ve used the matrix to scale and the result is the same, if I understand what is happening when the stage is auto-resized, perhaps I can optimize the zoom in and zoom out effect.
Here it is the code for anyone that wants to try:
import openfl.display.Sprite;
import format.SVG;
import openfl.Assets;
import motion.Actuate;
import motion.easing.Expo;
import openfl.events.MouseEvent;
class Main extends Sprite
{
public var board:Sprite = new Sprite(); // board
public function new()
{
super();
addEventListener(MouseEvent.MOUSE_WHEEL, wheelEventHandler);
board.graphics.lineStyle(2, 0xCCCCCC);
board.graphics.beginFill(0xFFFFFF);
board.graphics.drawRect(0,0,700,400);
board.graphics.endFill();
addChild(board);
for (i in 1 ... 100) { // number of SVG's on the board
var item:Sprite = new Sprite(); // each item on the board
var itemSVG:SVG = new SVG(Assets.getText("img/openfl.svg"));
itemSVG.render(item.graphics);
item.width = item.height = 50;
board.addChild (item);
item.x = 650 * Math.random(); item.y = 350 * Math.random();
}
}
private function wheelEventHandler(event:MouseEvent):Void {
switch (event.type) {
case MouseEvent.MOUSE_WHEEL: {
if (event.delta > 0) { // wheel scroll up, scales up the board by 20%
Actuate.tween (board, 1, {scaleX: board.scaleX * 1.2, scaleY: board.scaleY * 1.2}).ease (Expo.easeInOut);
} else { // wheel scroll down, scales down the board by 20%
Actuate.tween (board, 1, {scaleX: board.scaleX * 0.8, scaleY: board.scaleY * 0.8}).ease (Expo.easeInOut);
}
}
}
}
}