Problem with bitmap 'camera'

8 posts

Flag Post

Hello everyone.

I’ve ran into a problem while trying to write a camera which basically shows a bit of another bitmap using copypixels, and then scaling it up to the size of the entire screen.

Problem I ran into? It stutters.

See this swf: http://www.newgrounds.com/dump/item/2dc3ca8ce55c2e47f1137e8b83924ad9

And this zip:
http://www.newgrounds.com/dump/item/256c5f58d129285780c86984958fc589

Use the arrow keys to walk to the left, when you reach the left edge the camera starts scrolling. It works fine, except for the stuttering. I’ve checked and doublechecked to make sure the camera is updated after the ‘knight’ and also that the camera is rendered after the bitmap containing the knight (so the knight’s position is updated when the pixels are copied).

Does anyone have a clue as to where I should look? Because I’ve spent about 2 hours pondering about this problem. Thanks in advance.

 
Flag Post

All I see is a blue rectangle.

 
Flag Post

1. Why should Camera extend BitmapData, instead of say nothing? Do you use inherited functionality? I can’t see if yes.
2. Allocating a new BitmapData once per Render call is BAD. You have its dimensions pretty much set once, and that’s all. And, you don’t seem to use “target” in that code. Stuttering is probably caused by you rapidly eating up memory with “new BitmapData()” each render.

 
Flag Post
Originally posted by vesperbot:

1. Why should Camera extend BitmapData, instead of say nothing? Do you use inherited functionality? I can’t see if yes.
2. Allocating a new BitmapData once per Render call is BAD. You have its dimensions pretty much set once, and that’s all. And, you don’t seem to use “target” in that code. Stuttering is probably caused by you rapidly eating up memory with “new BitmapData()” each render.

1. Check the Render function in the camera, 2a. same as 1.
I’ll have a look at the memory eating issue though, thanks for that tip!

 
Flag Post

On a side note, I’ve found a hacky solution. Calling Math.Ceil on the x and y variable of the copypixel rectangle fixes the stuttering. What this means, no clue.

 
Flag Post

Math.ceil returns the ceiling of the specified number or expression. The ceiling of a number is the closest integer that is greater than or equal to the number.

 
Flag Post

that’s probably because x and y in a bitmap are integers, so if you somehow don’t use integers, this will make them into that.

 
Flag Post
Originally posted by JohnnyBohnny:

Math.ceil returns the ceiling of the specified number or expression. The ceiling of a number is the closest integer that is greater than or equal to the number.

Either you’ve understand me wrong or you’re a true captain obvious here.

Originally posted by JohnnyBohnny:

that’s probably because x and y in a bitmap are integers, so if you somehow don’t use integers, this will make them into that.

I guess what happened was the bitmapdata ‘rounding’ the values, which made it jumpy. Anyways thanks for this info.