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 / Using a bitmap as a full screen background

Author
Message
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 27th Jul 2011 22:42
On page 537 (Listing 22.7) of the book "Hands On DBPro Vol 1",
the author LOADs the .bmp into an IMAGE, and then uses a SPRITE to show the background.

On page 404 of "DBPro Game Programming, Second Edition", J.S.Harbour also LOADs the space1.bmp into an IMAGE. But he displays it (page 403) in the Do/Loop with PASTE IMAGE (he does NOT use a Sprite).

My question:-
What is the best method to display a bitmap as the permanent background of a 2D game?
Thank you in advance, Geoff
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Jul 2011 23:52 Edited at: 27th Jul 2011 23:55
You could load and paste an image as width and height as the screen. If it is 3D you can texture backdrop "your_image number"


cheers.

I'm not a grumpy grandpa
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Jul 2011 01:23 Edited at: 28th Jul 2011 01:25
when the texture backdrop command was returned to dbpro (after the "hands on" books were published) i did some testing in comparing paste image, sprite/paste sprite, and texture backdrop and found the performance hits to be near-identical (if not precisely identical).

texture backdrop is basically a 2-in-1 command where it both scales and pastes the image. if you truly, and simply, want a static, fullscreen background for your game, then texture backdrop is, technically, the best.

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jul 2011 04:15
Generally we use PASTE IMAGE for large areas like the background and only use sprites when we want to detect certain areas (like around characters). If the whole background is a sprite we cannot use any of the sprite collision commands because the entire background would detect collision with any other sprite on the screen.

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 28th Jul 2011 18:51
Thank you for the speedy responses.
I will enjoy testing the alternatives.
Geoff.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Jul 2011 19:39 Edited at: 28th Jul 2011 20:48
Following on from what was said, texture backdrop is a good function for the purpose. Note that this textures the background of the current camera.

You should be fine with texture backdrop; but there are more CPU friendly ways to draw an image on the screen; just choose what is most convenient for you and your players.

If accuracy of screen co-ordinates is not important; you can quickly and easily take advantage of the accelerated Graphics Processing Unit to draw an image as a texture on a 3D plane, facing the camera using
or similar.

We are practically drawing 2 polygons and an image using the GPU, without having to calculate the screen co-ordinates; although you may choose to delve into [pick screen] commands and rotation calculations if you feel it is necessary. You don't even have to use as much as 2 polygons forming a plane, a single polygon can do the job with some maths.

Whether a 2D game or 3D game, a background is a background; your players do not care what goes in, they care about what they get out of it; therefore, nobody says you have to always use 2D commands for 2D games, don't be afraid to use the 3D commands as well.

For example drawing a shaded 3D sphere with an .FX shader is easier for your computer to do than drawing a filled 2D circle using dot commands. The industry is building the hardware to make use of that Z axis.

Note that there are faster 2D command functions available.

It sounds like overkill but the advantage is quite simply, render speed. It allows you to draw one, two even ten images on the screen without losing much performance; 20, 30, 50 images if you like, all the computer has to do is shade some polygons! How many millions of polygons does your graphics card support? -All this whilst also being able to use Texture Backdrop at the same time.

Compared to pasting sprites and images which slows down your CPU dramatically even for one image, and also Texture Backdrop, which only supports one image; this method is useful for special effects in the background, foreground, characters, entities, anywhere you like. You do not even have to use sprites for characters if you don't want to! You could ignore the Z axis and work with X and Y positions with 3D planes which support FX shaders and all of the 3D object commands. Furthermore, who says you have to use images instead of models or particles?

It is all up to you.

Finally, for advanced situations in the future, [texture screen] will give you FULL control over the screen; therefore when you get more experienced, you can control the GPU rendering process; draw your scene exactly how you want it, with backgrounds, movies, FX, dark, bright, blue, pink whatever.

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 28th Jul 2011 21:47
Thank you, Chris, for your detailed response.
I have to admit that it is a little bit out of my depth at the moment (all right, it's way out).
I am grateful and embarrassed to think of the trouble you went to, and I shall certainly follow up your links and suggestions.
Thank you, again, Geoff.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 29th Jul 2011 01:09
No problem, just let us know how you get on.

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 29th Jul 2011 23:34
Below, is the code of my current simple 2D program:-
(I may not have used the code button correctly).

When the user presses the space bar, the ship fires a bullet vertically.
The ufo moves from left to right near the top of the screen.
If the bullet hits the ufo, an explosion is shown.
This all takes place on a bitmap of outer space ("borrowed" from J.S.Harbour's Astro Gunner).

The program does work quite well. But you will see from my comments in the code that, the stability of the background depends on my having converted the loaded background image into a SPRITE.

I would welcome any improvement suggestions.
Geoff.
P.S. If anyone would like copies of the bitmap files, please let me know.
[/code]REM When the program is running, press Esc to exit.
REM My Settings are Full Screen Exclusive 800x600x16

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 ufoX As Float
Global ufoY As Float
Global ufoXamt As Float
Global ufoYamt As Float
Global missileX As Float
Global missileY As Float

loadGraphics()

Do
REM The following line (Paste Image back,0,0) isn't needed.
REM It doesn't help, regardless of whether or not
REM "Sprite back,0,0,back" is used in Function loadGraphics().
`Paste Image back,0,0

checkInput()
handleUfo()

Loop

Wait Key
End

Function loadGraphics()
Load Image "Space.bmp",back
REM The following line is needed to stabilise the background:-
Sprite back,0,0,back

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()
Show Sprite missile
missileX = 408
missileY = 550
Repeat
handleUfo()
missileY = missileY - 15
Sprite missile,missileX,missileY,missile
testCollisions()
Until missileY < -15
EndFunction

Function testCollisions()
If Sprite Collision(missile,ufo)
Hide Sprite missile
Set Sprite Image ufo,explode
Wait 800
Sprite missile,900,800,missile
ufoX = 0
EndIf
EndFunction
[code]
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 3rd Aug 2011 19:58
change the order of your code tags, /code comes last

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 4th Aug 2011 00:55
Thank you, Rich, for the tip on posting code snippets.
I am going to attempt to create one here (by clicking on the code button before I start typing, and again at the end:-



It doesn't look as though it's worked.
What am I getting wrong?
Any further help would be very welcome.
Geoff.
P.S.
A further question:-
Shall I wait for this thread to reach the bottom of the page before repeating my last posted question?
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 4th Aug 2011 00:57
Sorry, I can see now that it did work.
Could you help with my P.S. question?

Login to post a reply

Server time is: 2024-11-22 19:05:24
Your offset time is: 2024-11-22 19:05:24