Help With My Code

Previous topic - Next topic

James_Parsons

Hello, I have just started GL-BASIC for game development, and I would like to buy it if I can get used to it. I wrote a little code this morning, however it would not display my sprite

Code (glbasic) Select

START:
    LOADBMP "E:/Background.bmp"
     
MAIN:
    LOADSPRITE 0, "E:/Player.bmp"
    DRAWSPRITE 0, 100, 100
    SHOWSCREEN
    KEYWAIT


I am 99.9% sure my path is correct, my background shows
JSR $FFD2

MrTAToad

First off, I would get rid of all direct access - directly specifying a drive letter is baaaddd...

Once you end up with :

Code (glbasic) Select
START:
    LOADBMP "Background.bmp"
     
MAIN:
    LOADSPRITE 0, "Player.bmp"
    DRAWSPRITE 0, 100, 100
    SHOWSCREEN
    KEYWAIT


note that the parameters for LOADSPRITE are the wrong way around.

It should be
Code (glbasic) Select
LOADSPRITE "Player.bmp",0

Then check to make sure that the graphics are in the same place as the executable.

Poetronic

Hi James,

you might also want to have a look at the SETCURRENTDIR() command!

:)

Best,
P.
ILI-Blocks, my first game ever - please check it out! http://www.glbasic.com/forum/index.php?topic=8654.0

bigsofty

If your running on anything else but Windows, keep an eye on file name case sensitivity too.  ;)
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Darmakwolf

 :help:

Here, see my attached project! It will help you understand a basic loop in GLBasic. It loads a background and a sprite, and even deals with mouse coordinates! Please let me know if you don't understand part of it.

Jonás Perusquía

#5
You wrote
Code (glbasic) Select
    LOADBMP "E:/Background.bmp"
But you shouldn't use drive letters, since they sometimes change depending on PC, try with:
Code (glbasic) Select
    LOADBMP "../Background.bmp"
each ".." means "back to folder" so if your app.exe is inside of C:\Users\Me\app.exe
and your Background image is on C:\Users\Background.bmp
Try placing ".." without quotes before the file name as above, if your image is in the same folder as your app.exe then write only filename, if your background image is in a further folder than your app.exe, example:
C:\Users\Me\images\Background.bmp
Then use:
Code (glbasic) Select
    LOADBMP "images\Background.bmp"

These should not be used:
Code (glbasic) Select
    LOADSPRITE 0, "E:/Player.bmp"
    DRAWSPRITE 0, 100, 100

Since these commands are only for LOADSPRITE, ZOOMSPRITE, ROTOZOOMSPRITE and STRETCHSPRITE

You should better check out STRETCHSPRITE, for me, it is better because when using STRETCHSPRITE you can change width and height.

Code (glbasic) Select
    LOADSPRITE "Background.bmp", id  // id is any positive number
    DRAWSPRITE id, x, y // x, y positions
x=100
y=200


To use the image as background use this:

Code (glbasic) Select
GETSCREENSIZE sx, sy
    LOADSPRITE "Background.bmp", 0
    STRETCHSPRITE 0, 0, 0 sx, sy    // first 0 is id, next ones are start x/y positions, then sx/sy are final positions.

GETSCREENSIZE returns the screen resolution for your app (as specified in project options) and places it in the variables sx## and sy##.

Do not forget to use SHOWSCREEN, i always do :D

Also, you should check out the SETCURRENTDIR(); command :)

Press F1 while using GLBasic SDK :)
<HTML><BASIC><EC>
Be free and do good things

spacefractal

also uses the "Media" folder to put on your files, which is the most correct way to and add a SETCURRENTDIR("Media") near the top. All files for compatible sake should been in the Media folder for games.

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Brick Redux

A big handy tip for all new users.

Part of your code not doing what you want it to do in run time? Place the END command inside your IF/ENDIFs that seem to be ignored in your running project. ( Or SUBs & FUNCTIONs )

Run your code & if it exits at the given point where your mysterious IF/ENDIF was checked you`ll know its being read but misinterpreted.  Go back and look at what youve coded to happen, then step backwards and look at whats leading to it being ignored.

Its also handy to have a pen and pad handy.  Pen and paper can save lots of time by scribbling down your plan and formulating that into code later on screen.  When it doesnt work - look at what you penned down. 

If the search option here fails to help you just ask as there are many here who can help you.
A mournful owner of a HP HDX18 Laptop that has died...FECK!

Marmor

so much help , but no reply  :noggin:

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Darmakwolf

Quote from: Marmor on 2013-Sep-28
so much help , but no reply  :noggin:

yeeeah I've come to expect that. Most times when new people post for help, they take the help and run. lol.

Moru

It's about persistence. We humans often lack it :-)

Youth: Oh cool, a new programming language! Oh, I have to see this movie! Wait, you are going to the burger-place? GIRLS! (or BOYS!)

10 years later they come back to programming having kids and a job and about 10 minutes of free time in the evenings :-)

Heiko

But....after these ten years he can display the sprite...

And in a world of 4D in future he create a new game genre and become a millionaire.

Schranz0r

Quote from: Heiko on 2013-Oct-11
But....after these ten years he can display the sprite...

And in a world of 4D in future he create a new game genre and become a millionaire.

Like Notch  :o
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

mrplant