Page 1 of 1

Quite new to PB, got some questions...

Posted: Sat Oct 09, 2004 7:27 pm
by GBeebe
First off I'd like to say that PB looks very prommising. Enough to make me stop writing in VB 6 & .Net. I love the fact that I can actually make stuff for my Linux box now. So I'm hoping to be able to convert my VB games to PB so that they can run under Linux as well, and with better performance.

Anywho i got a couple of questions that might be easy enough for some of you to quickly answer.

I don't quite think I fully understand the IncludeBinary() thing. Where It's supposed to be located (the statements) and how to use them after inclusion, like LoadSprite.
I saw a sample that someone posted the other day, but now I can't find it. :oops: Trust me... I looked and looked.

I immageine after a bunch of IncludeBinary() statements, that my EXE would start to get pretty big. Is there a way that PB can load a sprite from a variable? Like say if I have an external binary file that I made with all my images in it. and then loaded a portion of that to a variable.
I'm not even quite sure I can do that yet either. I haven't messed with opening files and loading stuff into variables in PB yet. But I've done it in VB, so if it's possible I guess I'll figure it out.

Another way I thought of getting around that was to IncludeBinary() a blank bmp of a fixed sprite size or multiple Includes of different sizes. Open the Binary file and then start drawing on the sprites, which brings me to my 3rd question.

Is there a way to draw on sprites created with LoadSprite()?

That about it for now guys. Thanks in advanced.

OH, is there any good tutorials on interfacing with the windows made with the Visual Designer? I have yet to figure that out. It seems to be totally different from VB where you just double click on a control (you guys call them widgets, i guess) and it brings up the code area for that and you just select the event in a dropdown box and start typing away.

Thanks again guys.


GBeebe

Posted: Sat Oct 09, 2004 8:07 pm
by dontmailme
So many questions !!!

Look in the help at .....

catchsprite()
startdrawing(spriteoutput))

Will help to start you off :)

Good luck !

Posted: Sat Oct 09, 2004 8:27 pm
by freak
> Is there a way to draw on sprites created with LoadSprite()?

To draw with the 2dDrawing commands on it, do "StartDrawing(SpriteOutput(#Sprite))"
If you want to draw other sprites on it with the commands of the
Sprite library, do "UseBuffer(#Sprite)"
After that, all DisplaySprite() and similar commands happen on that sprite instead of the screen.
Don't forget "UseBuffer(-1)" at the end, to draw at the screen again ;)

About IncludeBinary()

You should always put it in a datasection. The file will then be included in the
executable, and loaded into memory with the program code.
The best way to access that file is to put a label right in front of the
IncludeBinary (also inside the DataSection!) and use the pointer to
that label.

Example:

Code: Select all

DataSection

  MyImage1:
    IncludeBinary "sprite1.bmp"

  MyImage2:
    IncludeBinary "sprite2.bmp"

EndDataSection
You can now access these with all the Catch[...]() commands.
There is CatchImage(), CatchSprite(), CatchSound(), ...

CatchSprite(#SpriteNumber, ?MyImage1)
(note the ?MyImage1, this gives you the address where MyImage1 label is in memory)

Simple as that. The sprite now contains that 'sprite1.bmp' file.


About the Visual designer:

Go to 'Options' and select 'Include event loop'. The generated code will
then contain lines like this:

Code: Select all

    If GadgetID = #GADGET_0
      Debug "GadgetID: #GADGET_0"
      
    ElseIf GadgetID = #GADGET_1
      Debug "GadgetID: #GADGET_1"
      
    EndIf
Replace those Debug statements with the code you want to be executed
when there is an event for that gadget.
For some gadgets you can check which type of event it was. See EventType() command help for that.

I don't know of any tutorials for that. Just play around with it and ask a few questions here if you have trouble :)


Timo

Thanks

Posted: Sun Oct 10, 2004 8:35 pm
by GBeebe
Hey, Fr34k, thanks alot.

Posted: Mon Oct 11, 2004 1:21 am
by TheBeck
Will GrabSprite() get a sprite from another sprite after UseBuffer(#Sprite)?
I am at work or I would try this myself.

Posted: Mon Oct 11, 2004 1:49 am
by freak
Yes, it will grab from the sprite selected by UseBuffer()

Posted: Mon Oct 11, 2004 2:19 am
by freak
GBeebe:

I realize i didn't answer your question concerning the growing executable size
when including much files. Here is what i do:

Go to the tools section of my site: http://freak.purearea.net/tools/
The second from the bottom is called "PackFile". If you look at it's source,
you'll see that it is really small. What it does is, it uses the PB Packer
commands to compress a file. It then creates a new file, where it first
writes the size of the uncompressed data, and then the compressed data.

Now that newly created *.pak file is the one i include with IncludeBinary,
just like shown above.

I then include this procedure into my sourcecode as well:

Code: Select all

Procedure.l UnpackIncludeFile(*CompressedData)
  Static *UncompressedData
  
  If *UncompressedData                        ; Free the memory from the last call (if there was any)
    FreeMemory(*UncompressedData)
  EndIf
      
  OriginalSize      = PeekL(*CompressedData)  ; read the original size
  *CompressedData   + 4                       ; move away from the size value to the packed data
  
  *UncompressedData = AllocateMemory(OriginalSize) ; allocate enough memory
  
  If *UncompressedData
    If UnpackMemory(*CompressedData, *UncompressedData) ; uncompress the data and return the address
      ProcedureReturn *UncompressedData
    EndIf
  EndIf
  
  ProcedureReturn 0
EndProcedure
It simply reads the original file length from the included file and uncompresses
it again into a new memory block.
It then returns that new memory location of the uncompressed file, so
it can be used for example in CatchSprite().

Assuming I included a compressed sprite at the label "MyImage", i can
then simply do this:

Code: Select all

CatchSprite(#MySprite, UnpackIncludeFile( ?MyImage ))
This saves lots of executable size.
Remember, even though the compression of the file takes a lot of time,
the uncompression is done almost instantly, which makes it perfect for this
thing. The compression is also very good. (except for files like jpg, which
are allready well compressed.)

That's it..

Timo

Posted: Mon Oct 11, 2004 5:21 pm
by fsw
Freak,
actually I do the same except I use the normal CreatePack() command, because the packed file contains both sizes: compressed and uncompressed.

Maybe it's a dumb question but I would be interested to know why you didn't use CreatePack().... maybe there is a reason I don't know about :wink:

bye

Posted: Mon Oct 11, 2004 5:52 pm
by freak
Quite simple:
When i first wrote that code, there was no CreatePack() command :wink:
And since it worked.. i never thought of another way.