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.

Newcomers DBPro Corner / Problem with getting a background bitmap to persist in a sprite shooting game.

Author
Message
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 29th Apr 2011 19:06
I am in the first stage of building this game.

My current problem:-
In the code below, you will see that, in order to prevent the background image flickering or disappearing, I have had to include the statement "Paste Image back, 0, 0" in three places:-
In the Do/Loop, and twice more in the "fireBullet()" function.

Is there a better way to achieve this, please?
I would also welcome any other guidance on my present code as far as it goes.

Thank you, Geoff.


(It will be apparent from the first 5 globals that I am using a bitmap background, and 4 sprites.)

Hide Mouse

Global back As Integer = 1
Global plane As Integer = 2
Global missile As Integer = 3
Global ufo As Integer = 4
Global explode As Integer = 5

Global ang As Word
Global ufoX As Float
Global ufoY As Float
Global ufoXamt As Float
Global ufoYamt As Float
Global explosionX As Float
Global explosionY As Float

loadGraphics()

Do
Paste Image back, 0, 0 `needed
checkInput()
handleUfo()
testCollisions()
Loop

Function loadGraphics()
Load Image "Space.bmp",back `**I thought only this one was needed.

Load Image "Ship.bmp",plane
Sprite plane,400,550,plane
OffSet Sprite plane,32,32

Load Image "Ufo.bmp",ufo
Sprite ufo,900,750,ufo

Load Image "Missile.bmp",missile
Sprite missile,900,800,missile
OffSet Sprite missile,12,5

Load Image "Explode.bmp",explode
Sprite explode,900,850,explode

EndFunction

Function handleUfo()
ufoY = 50
ufoXamt = 2
ufoX = ufoX + ufoXamt
If ufoX > 800 Then ufoX = 0
Sprite ufo,ufoX,ufoY,ufo
EndFunction

Function checkInput()
If SpaceKey()
fireBullet()
EndIf

EndFunction

Function fireBullet()
x = 408
y = 550
Repeat
handleUfo()
Paste Image back, 0, 0 `*****needed
y = y - 15
Sprite missile,x,y,missile
testCollisions()
Until y < -15
Paste Image back, 0, 0 `*****needed
EndFunction

Function testCollisions()
If Sprite Collision(missile,ufo)
Hide Sprite ufo
Hide Sprite missile
Sprite explode,ufoX,ufoY,explode
EndIf
EndFunction
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 29th Apr 2011 21:16
Texture a plane with it, position the plane in the proper place in front of the camera to represent the background.

If you have to move the background along with player movement use SCROLL OBJECT TEXTURE and scroll it in the desired direction.

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 29th Apr 2011 23:36
Thank you KISTech, for your quick response.
I seem to be out of my depth here. I suspect that your suggestions relate to 3D programming. I should have made it clearer that I haven't got very far with "2"D yet.
The program I'm trying to build is very loosely based on J S Harbour's "Astro Gunner" (His book:- "Dark Basic Pro Game Programming, 2nd edn.").
In that 2D program, he pastes the background image only once (at the top of the main game loop), and the background is stable all the time.

If I run my program with only one "Paste Image back, 0, 0" in the Do/Loop, whenever the player presses the space bar to fire a missile, the background disappears completely.

Does this help to describe my problem?
Geoff.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 30th Apr 2011 01:36 Edited at: 30th Apr 2011 01:39
I think you're missing a "sync on" and a "sync rate 60" at the beginning of your program. You will also need a "sync" in your loop right at the end, like this



Oh and please post your code in snippets like this [ code]yourcode[ /code] without the spaces in the code tags.

A clever person solves a problem, a wise person avoids it - Albert Einstein
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 30th Apr 2011 05:44 Edited at: 30th Apr 2011 05:45
Two thoughts...

Use the TEXTURE BACKDROP command to add a background to your game.

Here is an example:



Use the SET SPRITE command to stop the sprite from erasing the pasted backdrop.

Here's an example:


Either method works without re-pasting the background in your main loop.

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 30th Apr 2011 18:58
Thank you Hodgey,
I have tried your suggestion to use Sync statements, and the background does stay in place while the user presses the space bar, but unfortunately, the ufo and missile images do not show at all.
I am sure that this will be caused by my poor coding in the rest of the program.

Thank you Rich,
Your first suggestion gives the error message:- "This command is now obsolete". (I am using DB pro version 1.055).
Your second suggestion works fine, and I like with the starry background it produces.

But my Space.bmp was obviously artist produced, and I would like to get it to behave itself. My present plan is to continue studying J.S.Harbour's program.

All help will be gratefully received. Geoff.
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 30th Apr 2011 21:31 Edited at: 30th Apr 2011 21:58
Quote: "This command is now obsolete"


Yes, it was taken out for a while, but is back in now, with the newer versions.

EDIT: If you would post your media, we could all check the code. Aside from that, I'll check with "alternative" media.

This code works, but it uses alternative media. As Hodgey suggests, including sync commands makes sure you show your sprites when you want them to be seen.



Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 6th May 2011 23:12
Thank you, Rich, for your help.
I have managed to get my 5 .bmp's to work, by substituting them for your temporary graphic methods.

I shall now enjoy developing my program from a sound start.

Thank you all, Geoff

P.S. I couldn't discover how to post my .bmp's, but I don't expect anyone will be waiting anxiously to see them.
If anyone is, please let me know how to post them.

Login to post a reply

Server time is: 2024-11-16 19:10:31
Your offset time is: 2024-11-16 19:10:31