How do I put a camera on a separate window without lag?

107 Views Asked by At

The current way I'm doing it works, but is really heavy on performance, and I'd like to reduce the lag as much as possible.

Basically I'm copying the pixels of said FlxCamera onto an FlxSprite, and then I'm rendering that FlxSprite's pixels to a normal Sprite (openfl.display.Sprite), which then gets put onto the window. The lag doesn't seem to be coming from putting the camera onto an FlxSprite, it seems to be coming from putting the FlxSprite onto the Sprite (this is all in the update function btw). Is there a better way to put the FlxSprite onto the Sprite without having to copy the pixels every single frame? Or possibly a better way of copying the pixels that lags less?

This is the current code for it (just the FlxSprite to Sprite part):

notesSprite.graphics.clear();
notesSprite.graphics.beginBitmapFill(cameraSprite.pixels, new Matrix());
notesSprite.graphics.drawRect(0, 0, cameraSprite.pixels.width, cameraSprite.pixels.height);
notesSprite.graphics.endFill();

I've tried removing endFill(), nothing changed. I've tried removing drawRect() from update and only calling it once but that made the Sprite empty. I've scrolled through all the functions and variables to see if there was another way, but it didn't seem like it.

running clear() does seem to reduce the lag a lot, but considering I have a really good pc and it's still bringing me down to 60 fps, I wanna make sure the game is playable on other people's pcs that may or may not be as good. I've yet to test this on a worse pc (I'm gonna send a build to my friend soon so he can test it), but seeing as I'm working with a rhythm game I wanna make sure that the fps stays at 60 or higher constantly.

0

There are 0 best solutions below