Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Scrolling HUGE bitmaps.

Author
Message
Cassi
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 13th Oct 2003 12:08
I'm writing a game that requires HUGE bitmaps to be scrolled but I'm finding it prohibitively slow I think it may be the way I'm doing it so I was wondering if there was a better way.

My bitmap is made up of tiles 64 x 64 pixels and can be up to 100 x 100 tiles.

At the moment I have drawn the 'tiles bitmap' to bitmap1 then drawn the 'world bitmap' (made of tiles and can be up to 6400 x 6400 pixels) to bitmap2, deleted bitmap1 and then SET CURRENT BITMAP 0.

I have then grabbed bitmap2 as an image to paste but it is far too slow.

Originally I tried just grabbing an area the size of the screen to paste but calling GET IMAGE in each game loop to grab an image the size of the screen (1280 x 1024) reduced the game engine from 200+ FPS to 1 frame in 5 seconds!!!

Obviously both methods I've tried are not practical. So, can anyone tell me a better way to do it?

Thank you.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Oct 2003 13:11
You are pasting too many tiles in 1 go, and instead of get image, you could use copy bitmap. I find this hard to explain without pictures, and I have no upload space here, so I shall try to explain the technique as best as I can.

Screen 1 would be a double wide screen of screen 1. (Double wide if you are scrolling horizontally, double high if you are scrolling vertically.) Plus 1 row of tile map size.

Eg:
This is for left to right scrolling.....

Screen 0 = 1280 x 1024
Screen 1 = 2560 + 64 = 2624

Setup is slow.....(Do this before game begins)
Now draw 21 rows of tiles on screen 1 (for horizontal scroll)
copy bitmap 1....1280 * 1024 to bitmap 0

This is where things speed up.....

Now you can wait for the player to move. (No need to draw all the time)
As the player moves along, you copy Bitmap, but the X increases, that gives you a scroll effect.
When the player moves a certain distance, depending on how fast he moves...lets say 32 pixels for now. Do this.....

2nd time just draw a row of tiles on row 22 (After the first set)
Just 1 vertical row that's all. Faster!

Now wait again.

When the player is travelling on row 22 you do something odd!

Draw a set of vertical tiles on row 1 (Yes row 1) but the array you are drawing is for a completely new screen. So the tile set would actually be tilesw for row 42 (Something like that)

And when he is 32 pixels along in row 22 you draw a vertical set of tiles on row 23.

When the player is travelling on row 23, draw a vertical set of tiles on Row 2 but the tiles would be for 43.

Do you see the pattern?

You are drawing to the end of the map, and to the beginning of the map.

When the player has scrolled all the way to the end of screen 1, you will have completely drawn the next screen! You can then copy bitmap from x=1..the beginning again. Like a conveyor belt. The whole process starts again.

I hope you understand all this.

Pincho.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Oct 2003 13:25 Edited at: 13th Oct 2003 13:27
If you are clever, the above can be changed so that you draw just 1 tile at a time (Maybe 2), moving downwards 64 pixels each time with the tile Y coordinate.
Cassi
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 13th Oct 2003 15:59
OK - I think I understand, although I need to re-read to properly digest it.

I will be scrolling both horizontally and vertically but I think (hope!) it should just take some minor modification to adjust to suit.

Thanks for your help.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th Oct 2003 16:09
2D is always gonna be slow, especially with anything like a decent resolution. Have you considered 3D instead? - like 3D plains instead of images. You simply make a 3D plain, and texture it with the image and set the transparency etc - means you can have translucency etc.

For example, your backdrop could be made from a matrix which is scrolled and updated in a similar way to what your doing now, if the player had move a whole tile, you'd retexture the matrix and update it. This would proove much faster, and will allow any screen resolution.

I recently converted a 2D engine to 3D in the space of 30 minutes, the FPS gain was about huge.


Van-B

Cassi
20
Years of Service
User Offline
Joined: 6th Sep 2003
Location:
Posted: 13th Oct 2003 17:33
My current project is more suited to 2D.
That's not to say I have ruled out 3D I am still considering it and may even end up going that way especially because the 2D sprite collision is crappy!
I am going to stick with 2D for now but you never know I may end up going with 3D and ignoring the Z axis.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Oct 2003 18:27 Edited at: 13th Oct 2003 18:28
Horizontal, and vertical would need you to refine my example to it's absolute minimum tile paste. If you can walk anywhere you want you need a huge bitmap 2*Width + 64 pixels / 2*Height + 64 pixels. Massive! Then you need to cleaverly optimize pasting of tiles. You might be able to do this with just 4 tiles pasted per loop. That's not bad. It would run on most computers I think. You should try array collision, and not sprite collision. I wish you luck! It sure would be a nice engine!

Pincho.
Pincho Paxton
21
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Oct 2003 18:36
Van-B's method would be better though. Special effects and stuff would be much nicer.

Login to post a reply

Server time is: 2024-04-27 22:45:55
Your offset time is: 2024-04-27 22:45:55