-
Notifications
You must be signed in to change notification settings - Fork 153
Description
I've only tested on mac, but adding the following to the FlxCamera demo brings the fps from 60-62 down to 20-23
import flixel.math.FlxRect;
import flixel.addons.display.FlxSliceSprite;
@:forward
abstract BorderSprite(FlxSliceSprite) from FlxSliceSprite to FlxSliceSprite
{
inline public function new (x = 0.0, y = 0.0, width:Float, height:Float)
{
this = new FlxSliceSprite("assets/Border.png", new FlxRect(15, 15, 20, 20), width, height);
this.x = x;
this.y = y;
#if debug
this.ignoreDrawDebug = true;
#end
}
}
Edit: upon further investigation, the above code struggles because when width and height are 1280 by 960, this is using 25,480 vertices to draw this. By adding the following lines, the vertex count goes down to 72!
this.stretchBottom = true;
this.stretchTop = true;
this.stretchLeft = true;
this.stretchRight = true;
this.stretchCenter = true;
This still doesn't explain why the performance issue was only worse when FlxG.drawDebug is enabled, though. but the above change eliminates the performance issue, entirely. Perhaps drawDebug is a red herring, and the usual slowdown from drawDebug made a more noticeable impact when combined with the slowdown caused by the inefficient slice sprite vertices.
FlxStrip is capable of rendering a repeating image across, for instance:
final strip = new FlxStrip(20, 20, "assets/images/haxe.png");
strip.loadGraphic("assets/images/haxe.png", true, 100, 100);
strip.vertices = DrawData.ofArray([0.0, 0, 160, 0.0, 160, 80, 0, 80]);
strip.uvtData = DrawData.ofArray([0.0, 0, 2, 0, 2, 1, 0, 1]);
strip.indices = DrawData.ofArray([0, 1, 2, 0, 2, 3]);
strip.repeat = true;
add(strip);
However this may not be applicable to FlxSliceSprite, because it's not repeating the entire texture, but only a middle portion.
Whenever I make sliceSprites I typically make the middle sections as small as possible, as I expect them to be stretched, by default and i want image sizes to be as small as possible. I do think think it makes sense to make these stretch flags true, by default, given that seemingly insignificant factors like image size and rect size can have exponential impacts on the performance and memory of slice sprites