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 / My fist very very very dark basic program

Author
Message
Ian Hughes
20
Years of Service
User Offline
Joined: 29th Sep 2003
Location: UK
Posted: 3rd Oct 2003 17:35 Edited at: 3rd Oct 2003 17:36
this my fist very very baisc, dark basic program but still need some help

can anyone tell me were to find some imfrmation on how to change the letter "a" to my graphic so i can move it left and right
I now know i have to have my graphics in the same dir :o)
the keys i am using is z/x left and right and the m key to display the graphic

Spam UK
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 3rd Oct 2003 17:48
Okay, so first we're going to load the graphic file. Note it can be in a subdirectory within the directory as well so it doesn't have to be in the exact same as your source files. In fact, most people tend to make a "Media" folder and keep all their graphics and media files in that. We'll keep it in the same folder for now though.

To load the image we just use the code:

Load Image Filename, ImageNumber

You will want to replace Filename with the filename of your graphic and imagenumber with any positive number. For instance:

Load Image "a.bmp", 1

Now with that image loaded we can use the following command to paste it to the screen:

Sprite SpriteNumber, XPosition, YPosition, ImageNumber

We've already determined the ImageNumber as 1 from our previous line, and you've already written the code to find the X and Y positions so that just leaves the SpriteNumber which can be anything you like. We'll use 1 again.

Sprite 1, letterX, letterY, 1

Put that line in your loop in place of "text letterX, letterY, letter$" and it will work. Full source code attached. Hope this helps.


"Computers are useless they can only give you answers."
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 3rd Oct 2003 17:58
Just missed that bit about using m to substitute the graphic. This takes a little more work.

We're still going to load the image at the start of the program because it's faster to load everything first. We'll also define a boolean variable that will let the program know if we want to show the graphic or the text. A boolean variable will either hold True or False, DarkBASIC uses the values 1 and 0 respectively to replaec these.

Load Image "knight.bmp", 1
ShowGraphic As Boolean

Now we have loaded our image and defined a boolean variable. Now we want to make it when the user presses "m", it changes to the graphic. This is simple.

if inkey$()="m" then ShowGraphic = 1

We just change the boolean to equal 1 (True), now to actually display the graphic or text we do a test to see if the boolean is true or false.

If ShowGraphic = 0 Then text letterX, letterY, letter$
If ShowGraphic = 1 Then Sprite 1, letterX, letterY, 1

If it's False (0) then display the text, if it's true (1) then display the graphic. To change it back to using the text it's as simple as making the boolean equal 0 again.

Full source attached.


"Computers are useless they can only give you answers."
Ian Hughes
20
Years of Service
User Offline
Joined: 29th Sep 2003
Location: UK
Posted: 3rd Oct 2003 18:18
Hi
Thanks for yor post. Ok I have type in your code and it keeps bombing out and ill not execute the program.


this is what i have typed

Rem * Title : 30.09.2003
rem ***** Moving left to right whith the letter "a" or graphic ***
rem ***** 2/10/03 ***

Load Image "knight.bmp", 1
ShowGraphic As Boolean
letter$="a"
letterX=300
letterY=400
letterm=100

do
cls
if inkey$()="z" and letterX>12 then letterX=letterX-20
if inkey$()="x" and letterX<600 then letterX=letterX+20
if inkey$()="p" and letterY>10 then letterY=letterY-10
if inkey$()="l" and letterY<4000 then letterY=letterY+20
if inkey$()="m" then ShowGraphic = 1

If ShowGraphic = 0 Then text letterX, letterY, letter$
If ShowGraphic = 1 Then Sprite 1, letterX, letterY, 1

loop

also my knight graphic is a bitmap no an image does this make any differce as i used load bitmap "kight.bmp) in my orignal code

I am using dark baisc

Spam UK
PoHa!84
20
Years of Service
User Offline
Joined: 2nd Oct 2003
Location: To your left.
Posted: 3rd Oct 2003 20:27
I'm not 100% positive, but I'm pretty certain that if you wanna do anything with a bitmap, then it has to be an image. I always use the following function that I found in the "room" example with dark basic:



Then, call the function like this (example.bmp would be replaced with the name of your .bmp file, and you could set the number to whatever image number hasn't been used)



Then again, I could be completely off. I hope this helps someone, at least...

Destroy you with my mind, I could!
skovron
21
Years of Service
User Offline
Joined: 14th Sep 2003
Location:
Posted: 3rd Oct 2003 21:32
What for load some picture into bitmap than read it from bitmap into image and delete bitmap to get image.

Firstly I thought you do it in that way couse you wanna establish size of picture, but do nothing with width and height so maybe its better do following:

load image FileName$, ImgNumber
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 4th Oct 2003 05:12
Well Load Image works for me with a bitmap so I don't know why it isn't for you. I simply copy/pasted your code and it ran fine.

Are you using DarkBASIC or DarkBASIC Professional?


"Computers are useless they can only give you answers."

Login to post a reply

Server time is: 2024-09-21 04:13:27
Your offset time is: 2024-09-21 04:13:27