PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Scrolling Background screens

Hello..
i am new to EDGELIB. I am developing a game for Windows Mobile 6 sdk ....
in my game i have to scroll the background using tiles of images . can an yone help me in this topic...

please give me step by step procedure or some sample code to get this .

thanks in advance .
Hi,

The following approach could suit your needs:
- Use a tilesheet which could contain 256 tiles in 16 rows (in a 16x16 matrix)
- Create a large tilemap array which fits your game 'world'
- Add scrolling variables, xscroll and yscroll. For example, xscroll can be a value from '0' to 'mapwidth_pixels - screenwidth_pixels'
- When rendering, determine which tiles of your tilemap fit within the screen, then get the matching tile from your tilesheet and blit the image to the screen
bcj · 30 Sep 2009, 12:03 UTC — Scrolling Background screens
thanks for your reply .
because i am a new learner of EDGELIB, i don't know the way of working with tileArray,and setting the world properties .
can you give another easy way or some code help to scroll a singe image(not as tiles) cotinuously as background.

cheers
Hi,

Here is a small sample with a player and a scrolling image. This sample only works properly if the image is bigger than the screen.

Code:

//Get scroll position from player (the player will be centered)
long scrollx = player_center_x - display->GetWidth() / 2;
long scrolly = player_center_y - display->GetHeight() / 2;

//Lock to screen edge
if (scrollx < 0)
scrollx = 0;
if (scrolly < 0)
scrolly = 0;
if (scrollx > image.GetWidth() - display->GetWidth())
scrollx = image.GetWidth() - display->GetWidth();
if (scrolly > image.GetHeight() - display->GetHeight())
scrolly = image.GetHeight() - display->GetHeight();

//Draw
display->BltFast(-scrollx, -scrolly, &image, NULL);
display->BltFast(player_center_x - playerimage.GetWidth() / 2 - scrollx, player_center_y - playerimage.GetHeight() / 2 - scrolly, &playerimage, NULL);


The variables image and playerimage are E2DSurfaces and assumed to be loaded. I hope this helps.
bcj · 28 Oct 2009, 17:59 UTC — Scrolling Background screens
Hai EDGE ,
thanks for your reply , i tried your code to get scrolling effect , but i can't get scrolling.

in my game i have 640x480 screen . and i have one background image of same size . so i have to scroll it on that screen.

please give me a simple way to scroll that image smoothly..

on that scrolling background , i have to move my sprite objects also . so give me the solution for that.

waiting for reply...
bcj
Hi,

If you need to scroll an image with the same size of the screen, you need to repeat that image horizontally or vertically (depending on your game).

To get more information on how to learn game programming techniques we recommend checking sites such as www.gamedev.net.
bcj · 02 Nov 2009, 19:02 UTC — Scrolling Background screens
hi...Edge
Thanks for your response ..
i tried to get scrolling background..but i didn't get it correctly.

so can you please help me in this issue...and give me some solution , that how to get scrolling effect of background.

my game having 640x480 size , and have one image.
we can use image repeatively and can get scrolling..
can you give me solution in this way...
or your suggested way of solution.

if possible give me some example code of repeating the image Horizontally and vertically.

Waiting for reply... Thanks in Advance
Hi,

Here is a small example on how to repeat an image to get a scrolling effect. Changing of scroll isn't part of this sample, but can be programmed easily be changing values when pressing the up, down, left and right keys for example.

Code:

long x, y;
for (y = 0; y < display->GetHeight() / backgroundsurface.GetHeight() + 1; y++)
{
for (x = 0; x < display->GetWidth() / backgroundsurface.GetWidth() + 1; x++)
{
display->BltFast(0 - (long)scrollx % (long)backgroundsurface.GetWidth() + x * (long)backgroundsurface.GetWidth(),
0 - (long)scrolly % (long)backgroundsurface.GetHeight() + y * (long)backgroundsurface.GetHeight(),
&backgroundsurface, NULL);
}
}