Question

I work on a 2D shooter game with lots of moving objects on the screen (bullets etc).

I use BitmapData.copyPixels(...) to render entire screen to a buffer:BitmapData. Then I "copyPixels" from "buffer" to screen:BitmapData. The framerate is 60.

private var bitmap:Bitmap = new Bitmap();
private var buffer:Bitmap = new Bitmap();

private function start():void {
    addChild(bitmap);
}

private function onEnterFrame():void {
    // render into "buffer"
    // copy "buffer" -> "bitmap"
}

The problem is that the sprites are tearing apart: some part of a sprite got shifted horizontally.

It looks like a PC game with VSYNC turned off.

Did anyone solve this problem?

UPDATE: the question is not about performance, but about getting rid of screen tearing.

[!] UPDATE: I've created another question and here you may try both implementations: using Flash way or BitmapData+copyPixels()

Was it helpful?

Solution

I feel your pain as I'm currently in the trenches developing my own game. At default settings, the Flash renderer produces horrible screen tearing / v-sync issues, regardless of what code you produce.

This is why I was pleased to have found the most simple, elegant answer, that wasn't re-factoring code (which doesn't help a single bit, the problem is the Flash player, not code).

Just enable Hardware Acceleration in your Publish Settings. There's two different options:

Level 1: Direct; and Level 2: GPU.

Read more about it at the official documentation: Specify publish settings for SWF files, and decide what option is best for your game.

Target market does play a factor here, if it's a serious game for gamers, you don't need to worry about possible performance issues, as most gamers have GPU's.

This article did not provide me with the solution specifically, but lead me in the right direction. BUT, if your game is going to be in a browser window, you might have to use the same technique of setting wmode to direct or gpu as well.

OTHER TIPS

First thing you might want to do is stop treating the Flash Player like it is DOS. The Flash Player is a highly optimized 2D game engine as it is and I don't really understand why you are trying to reinvent the wheel by copying lots of bitmap slices around. Of course you will have performance issues.

The Flash Player doesn't let you sync to any vertical or horizontal blank because the Flash Player simply doesn't have any concept of this.

I personally think that you should rethink you approach if you want 'smoother' animation. The Flash Player is certainly capable of this, you're just trying the wrong approach.

Don't save things to BitmapData, that will kill, absolutely kill your app. Bitmap Data is not very performant.

Make all your game elements in flash, as Sprites(or MovieClips if you must), and then work how flash was meant to work, as a vector animation platform. It was never optimized for 2d bitmap graphics. 2d vector graphics work well, and even if you import bitmaps they will work better moving around then they will rendered to a BitmapData object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top