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 / Having problems with Bitmaps

Author
Message
Dangerous
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Toledo, OH
Posted: 17th Jul 2005 10:23
I am new to DARKBasic but not programming. I have been casually programming for many years in a variety of languages. I have about 6 days left in the trail version of DARKBasic Pro and just bought the box version.

I am reading and performing the tutorials from the book, "Beginner's Guide To DARKBasic Game Programming", (I am on chpt 11 - Sprites). All has gone very well, I have used DBPro to make several simple games and other programs, however when I tried writing a simple program that use Bitmaps - major problems.

I couldn't get the sprites to draw to the screen using the "SPRITE" command. Thinking I may not understand the syntax or logic of the commands I loaded in the sample programs from the book, and they don't work correctly either! I found this baffling needless to say, so I began wondering if there may be a problem with my system.\

I downloaded and installed the latest windows patch, checked to make sure I had the latest DirectX version (I did), and downloaded the latest drivers from Invidia and installed. I then ran the DirectX diagnostic program and ran the DirectDraw tests just to verify there was no problem. I then tried the programs again, no luck, problem remained.

I either get no sprites or I get a solid blue background instead of my nice bitmapped one. I found that to solve this problem I had to redraw the entire background image each iteration of my game loop and then use "set current bitmap 0", draw the sprites then hit sync to update screen. (See attached code) While this works very well it is computationally expensive drawing the entire background, and my programs are drastically slower for it. So, curiously, I am wondering if anyone else has ever had this problem, and if so is there a better way? And are the programs in the book really incorrect or is the Trial version of DBPro crippled in some way?


PS: Also atached is the DirectX diagnostic output from the test I ran, which also shows system specks. Let me know if you see any hardware related issues.

If I am crazy, and the world is crazy, then I am normal.

Attachments

Login to view attachments
Dangerous
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Toledo, OH
Posted: 17th Jul 2005 12:08
There seems to be a problem with the way I loaded the source on my first post so I will just put it here for everyone to see.

Remstart
Project: Frog-Art
Created by: Dangerous

***** Main Source File *****
Remend

InitGame()
GameLoop()
EndGame()

end

function InitGame ()

set display mode 640,480,32
cls

sync on

hide mouse
position mouse 320,240

rem load background image
load bitmap "Background.bmp",1

rem load sprites
load bitmap "a.bmp",2
get image 2,0,0,20,100
load bitmap "b.bmp",3
get image 3,0,0,20,100
load bitmap "c.bmp",4
get image 4,0,0,20,20

endfunction

function GameLoop ()

do
copy bitmap 1,0,0,640,480,0,0,0,640,480
set current bitmap 0

X1 = mousex() - 50
Y1 = mousey()

X2 = mousex() + 50
Y2 = mousey()

FX = mousex()
FY = mousey()

DrawPlayer1(X1,Y1)
DrawPlayer2(X2,Y2)
DrawFrog(FX,FY)

sync

loop

endfunction

function DrawPlayer1 (X,Y)

sprite 2,X,Y,2

endfunction

function DrawPlayer2 (X,Y)

sprite 3,X,Y,3

endfunction

function DrawFrog (X,Y)

sprite 4,X,Y,4

endfunction

function EndGame ()

delete bitmap 1
delete bitmap 2
delete bitmap 3
delete bitmap 4

show mouse

endfunction

If I am crazy, and the world is crazy, then I am normal.
NanoBrain
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 17th Jul 2005 12:35
Dangerous,

I do not have the book, but if I am correct, it's source code examples are not tied together with DarkBasic Proffessional, but with DarkBasic Classic.


+NanoBrain+
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 17th Jul 2005 19:31 Edited at: 17th Jul 2005 20:01
Darkbasic Pro doesn't work well with the "load bitmap" command. The best way is to use "load image"... that way you don't have to use "get image" which is a time saver if the entire image is what you want to "get".

With DBP evertime you create a sprite or just move an already existing sprite you have to replace the background because it considers all sprites as 3D objects. The best way to replace the background is with a "paste image" command. It doesn't matter where you paste it (before a sprite move or after) because sprites aren't effected by it.

I'll play with your code and post a Darkbasic Pro friendly version in a bit.

Added later:

Your code was fine but there was one thing that caused errors like crazy. Function names cannot have spaces... not even right before the ()'s.

When using "load image" always put another ",1" at the end. That tells Darkbasic to not anti-alias the image it loads. Anti-aliased images look horrible because they change based on where their at on the screen. The syntax: load image "filename",imagenumber,1

In the do loop I erased the copy bitmap and set current bitmap and replaced it with "paste image 1,0,0". The syntax: paste image imagenumber,x,y

I also changed the EndGame() function with a simple for next loop so you can easily change one number to delete more images rather than add another "delete image ##" line.

Hope this helps.

Here's the new code:
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 17th Jul 2005 22:37
It depends. When loading bitmaps, you can get the width and height of the bitmap, but when loading an image, you cannot use these commands.

Immunity and Annihalation makes Immunihalation...

Login to post a reply

Server time is: 2024-09-23 23:21:00
Your offset time is: 2024-09-23 23:21:00