Author Topic: Help With My Code  (Read 4343 times)

Offline James_Parsons

  • Mc. Print
  • *
  • Posts: 2
    • View Profile
    • cpu68xx
Help With My Code
« on: 2013-Sep-09 »
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

  • Guest
Re: Help With My Code
« Reply #1 on: 2013-Sep-10 »
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.

Offline Poetronic

  • Mr. Drawsprite
  • **
  • Posts: 98
    • View Profile
Re: Help With My Code
« Reply #2 on: 2013-Sep-10 »
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

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2706
    • View Profile
Re: Help With My Code
« Reply #3 on: 2013-Sep-10 »
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)

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 354
  • Aoooooooo - the werewolves of London!
    • View Profile
Darmakwolf to the rescue... AGAIN!
« Reply #4 on: 2013-Sep-13 »
 :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.

Offline Jonás Perusquía

  • Mr. Polyvector
  • ***
  • Posts: 170
    • View Profile
    • Ditrabox
Re: Help With My Code
« Reply #5 on: 2013-Sep-23 »
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 :)
« Last Edit: 2013-Sep-23 by Jonás Perusquía »
<HTML><BASIC><EC>
Be free and do good things

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3932
    • View Profile
    • Space Fractal
Re: Help With My Code
« Reply #6 on: 2013-Sep-24 »
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 and The beagle Jam.

Offline Brick Redux

  • Mr. Drawsprite
  • **
  • Posts: 60
    • View Profile
Re: Help With My Code
« Reply #7 on: 2013-Sep-28 »
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!

Offline Marmor

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 926
  • 96A285CC
    • View Profile
    • my youtube channel
Re: Help With My Code
« Reply #8 on: 2013-Sep-28 »
so much help , but no reply  :noggin:

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5088
  • O Rly?
    • View Profile
Re: Help With My Code
« Reply #9 on: 2013-Sep-28 »
:D
I <3 DGArray's :D

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 354
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: Help With My Code
« Reply #10 on: 2013-Oct-11 »
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.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1792
    • View Profile
    • Homepage
Re: Help With My Code
« Reply #11 on: 2013-Oct-11 »
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 :-)

Offline c0d3r9

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 506
    • View Profile
Re: Help With My Code
« Reply #12 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.
Ryzen 5 3400G - MSI B450 Tomahawk - 16GB DDR4

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5088
  • O Rly?
    • View Profile
Re: Help With My Code
« Reply #13 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 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline mrplant

  • Mr. Polyvector
  • ***
  • Posts: 233
    • View Profile
Re: Help With My Code
« Reply #14 on: 2013-Oct-13 »
Hillarious!  :good: