Jump to content
  • Advertisement
Sign in to follow this  

Smooth scrooling a really big background

This topic is 3414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guy, Im using Flash CS3, and I have a really big background, it's jpeg image file, But when i scroll the background, it's not smooth. I did try to use a vector image which drawed by own Flash CS3, but it's the same, the screen was shock every second scrolling. Dose anyone tell me the mechanism to make smooth scrolling big background ??? Im really thanks so much !

Share this post


Link to post
Share on other sites
Advertisement
Yeah, here is code in Flash CS3

MvBackground.onEnterFrame = function()
{
if(Character.IsMoving)
{
this.x -= Character.Speed;
/*
just test with horizonal background scrolling and move background to
the opposite direction of character moving
*/

}
}

Share this post


Link to post
Share on other sites
Well I don't know Flash, but one method which may help speed up the render is spliting your background into tiles, and determining yourself which ones need to be rendered, and rendering only them.
Pseudocode (yeah my pseudocode looks like C, but just won't compile!):

Image tiles[X_SIZE][Y_SIZE];
TILE_SIZE = 32; // width and height of tiles
SCREEN_WIDTH = ...;
SCREEN_HEIGHT = ...;
SCREEN_TILES_X = SCREEN_WIDTH / TILE_SIZE;
SCREEN_TILES_Y = SCREEN_HEIGHT / TILE_SIZE;

int startTileX = screenPosX / TILE_SIZE;
int startTileY = screenPosY / TILE_SIZE;
int startTileXOffset = - screenPosX % TILE_SIZE;
int startTileYOffset = - screenPosY % TILE_SIZE;
int endTileX = min(startTileX plus SCREEN_TILES_X plus 1, X_SIZE);
int endTileY = min(startTileY plus SCREEN_TILES_Y plus 1, Y_SIZE);
int xTileCount = endTileX - startTileX;
int yTileCount = endTileY - startTileY;

for(int x = 0; x < xTileCount; inc x)
{
for(int y = 0; y < yTileCount; inc y)
{
drawTile(tiles[x plus startTileX][y plus startTileY], startTileXOffset plus x * TILE_SIZE, startTileYOffset plus y * TILE_SIZE);
}
}



P.S not certain this is quite right, might need to change some signs, or a +/-1 somewhere
P.P.S for some reason my + signs are not showing up in source tags, so I replaced them all with words instead, it might just be this computer but better safe than sorry.

Share this post


Link to post
Share on other sites
Quote:
Original post by bluntman
P.P.S for some reason my + signs are not showing up in source tags, so I replaced them all with words instead, it might just be this computer but better safe than sorry.
That is a bug in the preview. They display fine in the post itself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!