Smooth scrooling a really big background

Started by
3 comments, last by swiftcoder 15 years, 3 months ago
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 !
Advertisement
Well, how are you scrolling it? Post some code :)

"The right, man, in the wrong, place, can make all the dif-fer-rence in the world..." - GMan, Half-Life 2

A blog of my SEGA Megadrive development adventures: http://www.bigevilcorporation.co.uk

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
*/

}
}
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 tilesSCREEN_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.
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement