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! / Displaying text over background

Author
Message
Serain
18
Years of Service
User Offline
Joined: 17th Jul 2006
Location:
Posted: 25th Jul 2006 20:39
Hi,
I'm trying to display some text in my game using the "Print" command. But the text appears under my background (even though the "Print" command is after the command that draws my background). It might be because I'm using the "Sprite" command to draw my background, but I don't know how else I could do it.

rem Sprite 1 is the Ship
rem Sprites 3 - 502 are Bullets
rem Sprites 550 - 570 are Enemies
rem Sprite 2 is the Background


Sync On
Sync Rate 30
Hide Mouse

Set Display Mode 800,600,32

Set Image ColorKey 255,0,255

Load Image "ship.bmp",1
Load Image "enemy.bmp",2
Load Image "bullet.bmp",3
Load Image "background.bmp",4

Dim BulletX(500)
Dim BulletY(500)

Dim EnemyX(20)
Dim EnemyY(20)

ShipX = 400
ShipY = 500


Do

Cls

rem Display Background
Sprite 2,0,0,4

rem Mouvements
If LeftKey() = 1 And ShipX > 20
ShipX = ShipX - 20
Endif

If RightKey() = 1 And ShipX < 760
ShipX = ShipX + 20
Endif

If Inkey$() = "a"
Gosub Shoot
Endif

Gosub AddEnemy

Gosub UpdateShip

Gosub UpdateBullet

Gosub UpdateEnemies

Gosub EnemyBulletCollision

Gosub PrintScore

Sync

Loop


Shoot:
For i = 1 to 500
If BulletX(i) = 0
BulletX(i) = ShipX + 17
BulletY(i) = ShipY - 9
Sprite 2 + i,BulletX(i),BulletY(i),3
Exit
Endif
Next i
Return

UpdateShip:
Sprite 1,ShipX,ShipY,1
Return

UpdateBullet:
For i = 1 to 500
If BulletX(i) > 0
If BulletY(i) < 0
BulletY(i) = 0
BulletX(i) = 0
Endif

BulletY(i) = BulletY(i) - 25
Sprite 2 + i,BulletX(i),BulletY(i),3
Endif
Next i
Return

AddEnemy:
For i = 1 to 20
If EnemyX(i) = 0
EnemyX(i) = Rnd(700) + 40
EnemyY(i) = 10
Sprite 549 + i,EnemyX(i),EnemyY(i),2
Exit
Endif
Next i
Return

UpdateEnemies:
For i = 1 to 20
If EnemyX(i) > 0
EnemyY(i) = EnemyY(i) + 5
EnemyX(i) = EnemyX(i)
Sprite 549 + i,EnemyX(i),EnemyY(i),2
Endif

If EnemyY(i) > 600
EnemyX(i) = 0
EnemyY(i) = 0
Endif
Next i
Return


EnemyBulletCollision:
For i = 1 to 20
For j = 1 to 500
If Sprite Exist(549 + i) And Sprite Exist(2 + j)
If Sprite Hit(2 + j,549 + i) = 1
Delete Sprite 2 + j
Delete Sprite 549 + i
BulletX(j) = 0
BulletY(j) = 0
EnemyX(i) = 0
EnemyY(i) = 0
Score = Score + 10
Endif
Endif
Next j
Next i
Return

PrintScore:
Set Cursor 100,100
Text 1,1,"Score:"
Return[/quote]
m2zt
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 26th Jul 2006 20:26
Try using
Load bitmap "background.bmp",4 instead of
Load Image "background.bmp",4

In the do loop add
copy bitmap 4,0

And if you still cant see the text try removing the cls at the begining of the loop.

Futurama 2008
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jul 2006 20:32 Edited at: 26th Jul 2006 20:33
That won't help.

The reason you can't see the text is (as you suspect) because you are using a sprite as the backdrop.

There are two ways around your problem:

1) Don't use a sprite as a backdrop, try pasting the backdrop to a 3D plain and positioning it so that it fills the screen. There is a formula knocking around in code snippets somewhere to calculate the position for it.

2) Use bitmap fonts instead of the text command. I have got some bitmap fonts in the '2D all the way' section including functions to display them as sprites, or you can find them in the Free Media thread.


m2zt
19
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 26th Jul 2006 20:49 Edited at: 27th Jul 2006 03:37
Yes it will help.



The code is tested and the score does show up on the screen. But your methods work too. I just havent tried them myself.

Futurama 2008
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jul 2006 21:28
Perhaps when I said it won't help I should have phrased it: It may work but why the hell would anyone want the frame rate hit of copying a screen sized bitmap every loop?

It is an insane method that I wouldn't recommend to anybody.


Stupot
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: East Sussex
Posted: 26th Jul 2006 23:51
Does the background have to be a sprite?
Could it not be a BITMAP?. That way you could just put

Setting it to 0 will ensure that it stays behind everything else.

Tell me if I'm talking rubbish, and I'll get my coat.

-Stu
MoWL
18
Years of Service
User Offline
Joined: 27th Jul 2006
Location:
Posted: 27th Jul 2006 18:40
ok i got the same problem except i got a tile map which is a whole lotta sprites? how do i change them to images then? past image? wil it work? cauz im using the line command to make a selection box in my RTS...


Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 31st Aug 2006 23:52
ok, this is over a month old, but here are some answers

Serain: its simple to put the background inback of text


also with sprites, you can put text infront of sprites by manually pasting the sprites.


MoWL: never use sprites for tiles.
I made an example for someone, shows you how to do a tilemap


CreamPie
18
Years of Service
User Offline
Joined: 20th Jul 2006
Location:
Posted: 7th Sep 2006 03:35
Serain,

Is your background animated? If it is not, then do as CaveMan has stated in his last post.

However, only paste the background ONCE, before the loop...not within it. On top of this, make sure that anything that will be covering the background(bullets, ships etc) are sprites, and that
they are set to redraw their background.

Doing this will give you a background in which text can be placed upon, and it will drastically raise your FPS. Oh yes, take out the CLS command. This clears the video memory of everything, making the program to have to fill it back kup with everything again. However, if the BG is never cleared from memory, it will always be there and the processor will be freed from having to place it back into memory each loop. Instead, it can simply pull it from video memory straight to the screen.

If you need to place text somewhere, a way to clear it from the screen would be to get a rectangle clipping of your background, the size of the text string, and paste it over the text. This will have the same effect as using CLS and the repasting the background each loop, but without the side effects of a slow FPS! This is a very important topic to learn if you wish for your programs to carry a higher FPS.

Here is an example program that does not use ClS.



P.S. I have no compiler where I am currently at. Therefore, the program may be buggy. Check the get image commands within the fps printing function. I had no reference, therefore, the command may be typed out wrong.

>-Formerly known as NanoBrain-<

Login to post a reply

Server time is: 2025-05-15 07:09:38
Your offset time is: 2025-05-15 07:09:38