Author Topic: Sprite display query  (Read 2672 times)

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Sprite display query
« on: 2011-Jun-17 »
Hi,

I've found PeeJay's tutorials (and his website) which are just what I'm after but I'm stuck on Lesson 1 (!!!) Not a good start, I know!!

Code: (glbasic) [Select]
// --------------------------------- //
// Project: Lesson One
// Start: Friday, February 01, 2008
// IDE Version: 5.154
// --------------------------------- //

SETSCREEN 640,480,1
LIMITFPS 60

SETTRANSPARENCY RGB(0,0,0)

LOADSPRITE "l:\player.bmp",0

GLOBAL px=300
GLOBAL py=220

WHILE KEY(01)=FALSE
DrawTheScreen()
WEND

END

FUNCTION DrawTheScreen:
DRAWSPRITE 0,px,py
SHOWSCREEN
ENDFUNCTION

This code should simply display the graphic of the man in the centre of the screen. Note I've moved the graphic (player.bmp) into the root of my L drive so it should be pointing at the correct place but I'm getting a blank full screen.

Any help would be appreciated.

Thanks,

Steve.

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Sprite display query
« Reply #1 on: 2011-Jun-17 »
Hmm. When copied exactly that code works just fine on my Win7 GLBasic IDE 9.040 setup.

I suspect something is not OK with the file itself, since you've checked and probably doube checked the location.

Try using another bmp file, created in GIMP or another image manipulation application, to see if you have the same problem. If that doesn't work, try a PNG file instead. If that also makes no different then post in this thread the version of GLBasic you're using (under Help -> Info on the drop-down menu) and the platform (Windows 7, etc.) plus attach the player.bmp file you're using to the post, so the code can be tested with the exact same file you're trying it with.

MrTAToad

  • Guest
Re: Sprite display query
« Reply #2 on: 2011-Jun-17 »
Try :

Code: (glbasic) [Select]
LOADSPRITE "l:/player.bmp",0
and make sure that the graphic is in the same directory as the executable.
« Last Edit: 2011-Jun-18 by MrTAToad »

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Sprite display query
« Reply #3 on: 2011-Jun-17 »
It could be that GLB can't find the graphic where it's expecting it.

Try forcing the current directory at the beginning to where you know the file is:
Code: (glbasic) [Select]
SETCURRENTDIR("L:\")
If that doesn't work, add this line next to verify the file expected exists at the current directory:
Code: (glbasic) [Select]
IF NOT DOESFILEEXIST("player.bmp")
  DEBUG "File not found!\n"
ENDIF

Oh, and of course change your loadsprite line to:
Code: (glbasic) [Select]
LOADSPRITE "player.bmp",0
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 932
  • KodeSource
    • View Profile
    • KodeSource
Re: Sprite display query
« Reply #4 on: 2011-Jun-17 »
Ahh, I think MrTAToad is right!
Use '/' instead of '\', regardless of which OS you are on.
So, my suggestion would change to this:
Code: (glbasic) [Select]
SETCURRENTDIR("L:/")
[Edit]
'\' are used for escape sequences, such as in my DEBUG statement, '\n' translates to an ascii value of 10 which means 'new line'. 
They are used since there is no character representation for the lower ascii values, so no way to type them into messages.
« Last Edit: 2011-Jun-17 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Re: Sprite display query
« Reply #5 on: 2011-Jun-17 »
Aha! You've got it.

It's the '\' should be '/'. Been playing around with it for a while and couldn't understand why it still wasn't working.

It needs forwardslash, not backslash!!! Thanks you Slydog and MrTAToad. :good:

This now works.

As to version, I'm on 9.040. Are some versions more stable than others? (I'm aware this is actively updated and improved all the time) Which version is recommended?

Many thanks.


Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Sprite display query
« Reply #6 on: 2011-Jun-17 »
Oh, curious. Still works with '\' on this machine. Will have to remember to always use '/' just in case.

Most up to date official release is generally best unless you want to help with Beta testing, etc.


Offline Stevester

  • Mc. Print
  • *
  • Posts: 12
    • View Profile
Re: Sprite display query
« Reply #7 on: 2011-Jun-17 »
Thanks Ragaril,

I downloaded the GLBasic SDK Version 9 (main download link) - thinking this must be the latest stable release version (as opposed to beta?).

I tried Slydogs original suggestion and added SETCURRENTDIR(L:\") and receive a syntax error which is corrected by swapping '\' for '/'. (As he noted in his following post.


MrTAToad

  • Guest
Re: Sprite display query
« Reply #8 on: 2011-Jun-18 »
\ will work if the next character isn't a C escape code - otherwise it wont work...

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: Sprite display query
« Reply #9 on: 2011-Jun-18 »
Hi Stevester if you have torubles at the begginging whit this try this:

Select your image the make Control+C (Copy) and the into the Code make a paste Control+ V , or this couple of actions whit your rigth mouse button, and foget about the paths for the images.

Another way, and in a near future, probably you have to use SetcurrentDir ("Media") for mobile devices, you plave your media in this folder and don´t have any trouble.

Kinds Regards,
Iván J.