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 / How do I draw lines on a bitmap?

Author
Message
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 2nd Dec 2008 17:49
I have managed to display a jpg file which holds the image of a snooker table, and also a ball which moves around on the table.

I would now like to draw lines onto the table. But, so far, I have failed to do this.

Whenever I get the lines to appear, either the ball, or the table, and sometimes both, fail to show.

I am thoroughly bewildered with the use of images, bitmaps, sprites, creating, copying, setting current, etc. etc.

I would welcome any hints.
Thank you for reading this.
Geoff.
Not_Maindric
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Omaha, NE
Posted: 2nd Dec 2008 21:24
Could we see the code?

Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 2nd Dec 2008 22:03
I am pasting below, my current code, which shows the table and a ball, but not the line:-
Thank you for your interest. Geoff.


`Show the table:-
Table = 2
Load Image "SnookerTable.jpg", Table
Sprite Table,6,0,Table `needed

`Show the blue ball a x,y.
blue = 5 `Helps to identify the ball.
Load Image "BallBlue.bmp", blue `blue is the img num.
Sprite blue,100,100,blue

`I thought that setting current bitmap to the table would
`get the line to draw, but:-
`Set Current Bitmap 2 produces error "bitmap does not exist".

Line 10,10,800,600 `line does not show anywhere.

Wait Key
End
Talak
15
Years of Service
User Offline
Joined: 26th Nov 2008
Location: Australia
Posted: 3rd Dec 2008 00:53
You need to create the bitmap first:
create bitmap #,x,y
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 3rd Dec 2008 01:09 Edited at: 3rd Dec 2008 01:23
It's strange. I am getting weird results as well. It seems I can only get the line to draw behind the sprites. If I try to use the command Draw Sprites First. I can only see the line and not the the sprites. Then the only way to see the sprites is to use a double sync at the end of the loop, but this causes flickering.

I'll post up a basic example that everyone can test with.
[MEDIA]
Table


Ball



ok here is working code with the line behind the sprites


If I add draw sprites first, I loose the sprites


If I add a second sync at the end of the loop, I see the sprites but everything flickers. And you can see the blue backdrop coming on and off.



~Zenassem
Talak
15
Years of Service
User Offline
Joined: 26th Nov 2008
Location: Australia
Posted: 3rd Dec 2008 01:29
My post will likely show up late due to the approval, but you could try an overlay image. (Sorry if this double posts)

set bitmap format 21 `Uses transparency
set image colorkey 0,0,0 `Sets black to transparent
create bitmap 1,size x,size y `creates a new bitmap
ink RGB(255,255,255),RGB(0,0,0) `sets colour to white and background colour to black

`draw your lines here

`then get the image from the current bitmap
GET IMAGE Image Number, Left, Top, Right, Bottom, Texture Flag

set current bitmap 0 `sets the current bitmap back to default

`then create a plain and texture it with your image from the GET IMAGE command, and then:
set object transparency (object number),1
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 3rd Dec 2008 01:32 Edited at: 3rd Dec 2008 02:18
The only thing I can think of trying now is to load bitmaps, and get images. Trying that now

[EDIT]

ok loading Bitmaps, and getting Images works as expected!!!


Grrrrrrr!!!!! Except, When I tried to ADD a cls to the beginning of the loop.

////////

OK something is seriously broken with "draw sprites first" & CLS. I tried this code from the help files, and the red box, cannot be seen. The only thing i added was turning on manual sync. It didn't work without the sync either. If you add 2 syncs at the end you will see the sprite, but alas everything is flickering. If this isn't fixed, I am giving up on DBpro.

You will not see the red sprite


Adding 2 syncs you see the red sprite, but everything is flickering.


So I thought I would remove the backsave on the sprite to eliminate the flickering. While it prevented the backdrop from making it's presence know, it didn't stop the sprite from flickering.

With the code like this you will see a red square sprite


but if sprites are drawn first it dissapears



~Zenassem
naphta
15
Years of Service
User Offline
Joined: 2nd Dec 2008
Location:
Posted: 3rd Dec 2008 01:44
im not sure, but i think that the only thing you need to do is change the order in the DO cycle... like this:

sync on
sync rate 0

set image colorkey 255,0,255
backdrop off
set display mode 800,600,32

cls
load image "table.png",10,1
sprite 1,100,100,10


load image "ball.png",11,1
sprite 2,220,220,11

draw sprites first


do
cls 0

sprite 1,100,100,10
sprite 2,220,220,11
line 0,0,800,600

sync
loop

this way you are telling dark basic to first draw sprite 1 & 2, and after that DRAW the line, sorry for my bad english

fromt this:
line 0,0,800,600
sprite 1,100,100,10
sprite 2,220,220,11


to this:
sprite 1,100,100,10
sprite 2,220,220,11
line 0,0,800,600

remember that this is the order in wich the renderer draws the images...

if you code something like this:
line 0,0,800,600
sprite 1,100,100,10
sprite 2,220,220,11

the computer FIRST draw the line, then it draws sprite 1 OVER the line you first draw, in other words you delete the line, thats why you never see it. remember that when you use the SYNC command you are drawing to the screen using the double buffer technique or whatever is called, so the order in wich you call or draw the sprites and graphics is IMPORTANT.

i also think that the commmand DRAW SPRITES FIRST is only when you have polygons in the game, and you want the sprites to be drawn over the 3d graphics, i think that using this command is USELESS here.

i tried to write the better i can, im not very fluent writing english, if you dont understand something, tell me what it is and i will try to do better my friend.

be happy
naphta
15
Years of Service
User Offline
Joined: 2nd Dec 2008
Location:
Posted: 3rd Dec 2008 01:56
try this

sync on
sync rate 0

set image colorkey 255,0,255
backdrop off
set display mode 800,600,32

cls
load image "table.png",10,1
sprite 1,100,100,10


load image "ball.png",11,1
sprite 2,220,220,11




do
cls 0
sprite 1,100,100,10
sprite 2,220,220,11
line 0,0,800,600
sync
loop
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 3rd Dec 2008 04:43 Edited at: 3rd Dec 2008 05:06
@Naphta,

Did you try what you suggested? Did it work? What version of DBpro? Becuase I have tried it, and it doesn't matter the order of the the draw command vs. sprite command. While it sounds logical, DBpro never worked like this as far back as I can remember. It would always draw sprites after text, or 2d lines unless draw sprites first called. BTW Draw sprites first command is not just for when you use 3d objects. Look at the Help example for the command.

I am using version 7.0

But regardless something is broken.

This code, shows the line but you lose the sprites.


Once I find out what is broken I'll post it in the bug reports. Draw Sprites First will work as long as there is no CLS command in the loop. Once you add the CLS the you lose the sprites when using Draw Sprites first. You can see the sprites if you place two syncs in the loop, but of course that cuts the framerate in half, and you have flicker. So something is happening with the back buffer and the flip.

This is a serious bug, unless of course something changed in the updates and there is a reasonable explanation and or work around. Or perhaps I am delusional and forgetting something.


~Zenassem
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 3rd Dec 2008 09:37
Hi, I'm Geoff, the originator of this query.
It seems from your replies that there may not be one simple answer.
Playing about with your suggestions will keep me busy for a while.
I will let you know how I get on.
Thank you for all your help.
Geoff
naphta
15
Years of Service
User Offline
Joined: 2nd Dec 2008
Location:
Posted: 4th Dec 2008 00:40
@naphta:

sorry, you are absolutely right in your points... my mistake
i apologize for that, i was at work in a mac when i write that, and you are right, i wasnt sure if i was right nor i can test it...

i must not have done that, it only confuses Geoff more instead of helping him...

in the future i'll try first to make sure things work before posting.

again if I mispelled something or my writing doesnt make much sense
.... sorry for my bad english
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 4th Dec 2008 15:19
No problem, I will have to check prior updates. And IIRC dbpro sprites are actually 3d plains. I would like IanM to take a look at this. Perhaps he can see something we are missing. I'll post it later in the bug reports, with the info I have.


~Zenassem
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 5th Dec 2008 12:28
From Geoff (the originator).
I have experimented with each of the suggested methods, but still find that if I display a ball sprite on top of my snooker table, I cannot draw a line in addition to displaying the ball.

Am I correct in assuming that this is not possible?
(I have not been able to follow the latest posts referring to bugs)
Thanks again for your time.
Geoff.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 5th Dec 2008 13:04
I am still trying to determine the answer. I did post a bug report, but 2 responders are saying it's not a bug. They are also saying that draw sprites first is not meant to put sprites below other 2D, even though the help example suggests otherwise. I still disagree and think that something needs to be fixed. It really shouldn't be so trivial to accomplish what you are trying to do. The fact that the help files are plagued with errors only adds to the confusion.

From what I gather there is a way without using a cls in the beginning of the loop, leaving the backdrop on and coloring it, and rather than just loading the images and using them as sprites; you use get image like i did above. I still need to test it out though. I'll try to play arounf with it tonight.


~Zenassem
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 5th Dec 2008 13:27
Thank you for your speedy response.
Please don't feel you have to rush for me. I have plenty of other DB areas to keep me busy.
I shall however be interested in your results.
Thanks again, Geoff.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 6th Dec 2008 01:17
So far this is the best that I could come up with. Of course it's not clearing the entire screen every loop. The line is above all sprites ie. the ball and table. I still had to utilize draw sprites first, which everyone seems to swear is not intended to be used like this; but I can't seem to find any other way. It's a shame that it all dissapears if you add a cls. I even tried to keep turning the backdrop off inside the loop, but that didn't work.




~Zenassem
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 6th Dec 2008 01:26
You might try fiddling around with DRAW TO FRONT and DRAW TO BACK as well as DRAW SPRITES FIRST, I seem to remember having trouble with this on Digital Hangman. I think I ended up just moving the sprites offscreen where they couldn't be seen and using PASTE SPRITE to draw them on the screen, then you can just put everything in the order it needs to draw.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 6th Dec 2008 01:33 Edited at: 6th Dec 2008 16:19
Ok figured out what you need to do if you want to be able to clear the screen each loop. You have to use paste sprite. You will also probably want to remove the background restore (Backsave) via set sprite, since you would be drawing the entire background every frame. But here is the code.




~Zenassem
Geoff
17
Years of Service
User Offline
Joined: 10th Jul 2007
Location: Sheffield (U.K.)
Posted: 6th Dec 2008 13:26
Thank you, zenassem,
I have got your latest contribution working o.k.
I should now be able to replace your graphical representations of the table and ball with my .bmp and .jpg files.

For your interest, I want this facility to draw lines on the table so that I can see the relation between balls and pockets etc.

If I get into another mess, it is good to know that this forum is willing to help.
I may be back, Geoff.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 6th Dec 2008 15:11 Edited at: 6th Dec 2008 16:35
Your welcome, It's possible someone will come along with a better method. I tried the [draw to front] and [draw to back] commands, but it had no effect against other 2D components like the line.

One thing you may run into trouble with, especially when you add more balls, is the actual sprite priority. Esentially any of the sprites have the same chance of being drawn last. So look into the [set sprite priority] command, and ensure that you always have the table drawn first.

****
Finally, this type of game/demo would honestly be 1000 times easier in 3D. And you would have the ability to easily have any angle of the playing field you want. I am a die-hard 2d fan, but this is one of those times where I would seriously reconsider a 2d approach.

You are going to wind up with aome complicated situations even in a straight top-down approach in 2d. It can be done, but things that are completely arbitrary in 3d, will take a lot of work in a 2d approach. examples:

1)If you have it where a ball can jump over another ball, you will have to have really keep track of all sprite priorities.

2)If you texture the billiard balls with say a stripe and a number, it's goign to take a lot of work, to get the right animations. In essence the only semi-feasable way would be to take key frames of a 3d model to beign with. So why not just do it in 3d. Unless of course you are just going to use solid colors on the balls, and you aren't interested in ahadow/lighting, rotating textures etc...

3)Without a TP plugin, you are not going to get pixel perfect collisions in 2D with dbpro.

These are just a few of the headaches I think you could be in for, depending on exactly what you are trying to accomplish.


~Zenassem
DsarchyUK
16
Years of Service
User Offline
Joined: 21st Nov 2008
Location: UK
Posted: 11th Dec 2008 00:26
@Geoff
Have you looked at using Box2D, its a free pluggin floating around on the forums, would be ideal for a project like this.

@zenassem
Random Thought with a Jumping Cue ball, would this work:
With a ball jumping over another ball couldn't you just have a separate Image of a Cue ball larger in size (or even an animated sprite of a cue ball enlarging then shrinking)

Hide the cue ball when performing a jump
Play the Jump Sprite
Update the position of the Cue ball
Hide the jump sprite and then show the Cue ball image again.
1goto1
15
Years of Service
User Offline
Joined: 15th Jan 2009
Location: Canada
Posted: 20th Jan 2009 20:57
Quote: "I would now like to draw lines onto the table. But, so far, I have failed to do this.

Whenever I get the lines to appear, either the ball, or the table, and sometimes both, fail to show.

I am thoroughly bewildered with the use of images, bitmaps, sprites, creating, copying, setting current, etc. etc"


Tutorial 10 covers this very well.

Login to post a reply

Server time is: 2024-11-25 14:48:51
Your offset time is: 2024-11-25 14:48:51