News:

Function Finder  Find all the functions within source code files

Main Menu

Where to place img files?

Started by sadron, July 31, 2008, 04:59:58 PM

Previous topic - Next topic

sadron

I'm following the Space Invaders tutorial, but I'm having trouble with the img loading. I always get the code line error. Can any of you please tell me where I must place the files in my PlayBasic programs folder? Much appreciated.
"What quickly becomes obvious is that Witcher is very much a PC-exclusive game, which are typically designed to be as complex and unintuitive as possible, so that those dirty console-playing peasants don't ruin it for the glorious PC-gaming Master Race." - Zero Punctuation

kevin


   Howdy Ron, 

   You can load a file (be it image or other wise) form an absolute location or a relative locations.
  An absolute path will include the device letter, with folder and  file name all in one.   

  ie.
     LoadImage "c:\Program Files\PlayBasic\Projects\GFX\animal.jpg",1
     DrawImage 1,200,200,false
     Sync
     Waitkey

    While using absolute paths to load files it's often convenient when testing out an idea perhaps,  it's a real no no if you want to distribute a program for others to use though.   Since it's highly unlikely the file will be store in the exact same location on two or more different computers..    For example, the snippet posted above will only work for people who've installed PlayBasic to C: drive, in the Program Files folder.  (the default location it installs)   If you're Playbasic is installed to a different drive than the default, then the snippet will fail !   

     The better solution is to use relative paths.    When PlayBasic starts running any program,  PB sets the current 'base folder' of wherever the project files
are stored.   This means that we can load an file from within the project folder with having to the specify the 'absolute' path of the filename.   

     For example, if you open PB,   then save a new project using the Save As option from the file menu.    When saving a new project (one that doesn't previously exist)  we'll have to create a folder where PB will store all of the files pertaining to our project in.   This will help keep everything relating to our project in one convenient place.      So if we if create a new folder on the D:  drive in a folder called "MyGame"  or something

    Now since our project has it's very own folder stored some place on our computer,  when we compile and run our project (Using the F5 option) ,  PB will set current  folder to  "D:\\MyGame\"

    So if we stored and  image called "Ship.bmp" inside our MyGame folder we could load it by  LoadImage "Ship.bmp", 1   

     PlayBasic will try and locate this file within the projects current folder,  providing it exists (we copied the image into our project folder)  PB will be able to locate and load the media without issue.

     Personally,  what I do is take this one step further.  If i'm writing a program that requires 'media'  (be images or sounds or data files perhaps)  then  what i'll do is create a FOLDER within my project folder, which will house all of the particular media in one place.   For graphics media I normally create a folder called "GFX"     this changes loading slightly,  as we now have to include the 'folder' infront of the file name.   E.g..   LoadImage "Gfx\Ship.bmp", 1

    I've attached and example project folder to this post.  To use it, download and unzip it.   


thaaks

Hi Ron, if it's my Space Invaders tutorial that you are reading (this one) then your images should be placed into the same directory where you saved your Space Invaders project.

It loads the images relative to the project directory.

Hmm, I might add a description of creating and saving a project to my tutorial.

Cheers,
Tommy

sadron

Hi guys, thanks a bunch. Also it's sadron as one whole word, not Sad Ron (like he's sad or something) so, sa-dron or something like that. Anyway, again thank you ^^
"What quickly becomes obvious is that Witcher is very much a PC-exclusive game, which are typically designed to be as complex and unintuitive as possible, so that those dirty console-playing peasants don't ruin it for the glorious PC-gaming Master Race." - Zero Punctuation

kevin

 ahh... I was wondering about that :)