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! / changing Background

Author
Message
Red general
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: United Kingdom
Posted: 6th Dec 2002 18:05
I need help on backgrounds
I have DarkBasic v1, 1, 0, 0. I have made a sprite. This sprite walks around by the person pressing left, right, up down. It currently does this to the background of a forrest.
Here's the code

What I want to do is when I get near the right edge of the screan, the bitmap background (and the sprite)scroll left until the sprite reaches the left edge of the screen. then the sprite continues on and on getting near the right edge of the screen, it happens again. Can this be done? If so can any one tell me how?
Programmer for Christ
21
Years of Service
User Offline
Joined: 15th Nov 2002
Location: United States
Posted: 9th Dec 2002 19:56
Hey Redgeneral,
This does not sound too complicated.
Basically you need to set up a variable to record the current location of your sprite.
Then when the sprite's location gets close to the left side
move both the sprite of the background and the sprite of the guy to the left a little at a time.
Next when the sprite of the guy gets close to the left, stop changing their location each cycle.

In code it might look like this
spritelocation=x
IF spritelocation>600 THEN incrementalchange=10
IF spritelocation<50 THEN incrementalchange=0

x=spritelocation-incrementalchange


Also in order to scroll the background, you need to construct maybe a sprite that you can scroll as well,
Or better yet create a offscreen bitmap that is twice the width of your screen.
then just copy the region that you want and paste it for the background.

There are endless ways to do this, hope it helps

Your life is important,
Others care about you,
Especially the one who made you.

Login to post a reply

Server time is: 2024-04-26 08:30:43
Your offset time is: 2024-04-26 08:30:43