Quickie questions

Previous topic - Next topic

AndyH

Hi

For cross platform development, GLBasic looks to be an easy and simple way to do the job.  I'm impressed by it so far. :)  I've just a few questions which I wasn't sure about after looking through the examples and I could not find anything specific on the website that answers them so I hope you don't mind me asking these (perhaps obvious) questions here... I've also sneaked in a couple of enhancement requests...:)


SPRITES - does GLBasic attempt to use any hardware acceleration (eg: your 3D card) if it is available or is it always software rendering it?  I see there is an X_SPRITE but I'm not going anywhere near the 3D stuff yet.


LOADSPRITE, LOADSOUND and LOADFONT all use an index number that we must specify ourselves.  How does GLBasic handle these indexes internally.  For example if I use LOADSPRITE "Blah.png", 1000, will GLBasic store  1000 pointers in memory all null except for number 1000?  Is there a limit on the number of sprites you can have.  Every graphic item you want to display has to be a sprite too right?


Types look great.  Any possibility of expanding them in the future to allow for methods also, so the following might work:

Code (glbasic) Select
TYPE Enemy
  xpos
  ypos
  FUNCTION display: string$
  PRINT string$, xpos, ypos
  ENDFUNCTION
 ENDTYPE
 
 
 LOCAL test AS Enemy
 
 Test.xpos =10
 test.ypos =4
 test.display("Hello Object World")
 
 SHOWSCREEN
 MOUSEWAIT
This one is a bug/request - any chance of making the Backspace key work in the editor when holding SHIFT key?  I find it obstructive for it to do nothing when holding SHIFT.


Another enhancement request, unless I've missed it, you have to handle the animation of sprites yourself by switching the sprite number displayed.  Could you extend the DRAWSPRITE command set to handle an optional frame number too.  Eg:

Code (glbasic) Select
LOADANIMATEDSPRITE "SpriteStrip.png", width, height, 0  // width and height of each sprite in the sheet
DRAWSPRITE 0, x, y, frameNumber
LOADANIMATEDSPRITE would be a new command to specify the width and height of each sprite in the spritesheet.  The spritesheet would need to the right size, so for example I could make a PNG that is 64 by 32 in size.  I would split this into a grid of 16 x 16 giving me 4 columns and 2 rows.  GLBasic would number each cell in the spritesheet from 1 to 8 if I load it in with LOADANIMATEDSPRITE "SpriteSheet.png", 16,16, 0

You'd need to update other commands such as the SPRCOLL, GRABSPRITE etc to also be able to specify an optional frame number.  When a user omits this, then frame 1 is assumed - which you'd also need for normal sprites that have been loaded with the normal LOADSPRITE command.

I think this is much needed functionality so that I don't have to load each frame of my animations into separate sprites.


Finally, has anyone written a function to allow me to draw part of a sprite simply so that I don't have to use the STARTPOLY-POLYVECTOR-ENDPLOY commands?  I'm looking for something like COPYSPRITE spr, x, y, startx, starty, width, height  where x and y are where the sprite will be displayed on screen, startx and starty the part of the sprite to copy from for the witdh and height.  Would be handy to have something like this built in like we have for STRETCHSPRITE and ZOOMSPRITE.

AndyH

Just found this post which is a nice work around for loading spritesheets, but still requires each sprite to be in separate sprites numbers.

bigsofty

Yes, 2D Sprites are hardware accelerated if its available, software rendered if not.

This snippet...

http://www.glbasic.com/forum/viewtopic.php?id=731

Loads a sprite and its animated frames into an easily manipulated array data structure.

The last request, the Commands "GRABSPRITE " used in conjunction with "CREATESCREEN" provide the functionality that you require.

My advice is to create a bunch of functions in a custom library, based on the current command set, that cover the functionality that you require. With experience you will find that this is not a great task, as it may seem to a beginner in GLBasic. The tools are here for all that you ask, without extensions to the command set.
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)

AndyH

Quote from: AndyHSPRITES - does GLBasic attempt to use any hardware acceleration (eg: your 3D card) if it is available or is it always software rendering it?  I see there is an X_SPRITE but I'm not going anywhere near the 3D stuff yet.
I guess I should have done a test of this first...

Code (glbasic) Select
SETSCREEN 640,480,1
LOADSPRITE "test.png", 0

LIMITFPS 60
LOCAL x = 0
LOCAL tt = 1000

WHILE KEY(0)=0

IF KEY(205) THEN INC tt, 20
IF KEY(203) THEN DEC tt, 20

PRINT "total: "+tt, 0,0

LOCAL t
FOR t=0 TO tt
DRAWSPRITE 0, x, 200
NEXT
  INC x, 1
  IF (x>600) THEN x = 0
 
SHOWSCREEN
WEND
The test.png is a 64x64 alpha channel PNG.  Just a very simple test displaying tt number of sprites each loop with the cursor left/right for adjusting the value of tt.

I can easily get to 10,000 sprites on my PC before I notice any change in performance which is really good.  So I think I can safely say it's not software, and it's a bit of an obvious answer with a clue in the name DOH!  I'm thinking about entering the GPX competition, do you have an indication of how many 64x64 sprites the device can handle before the performance is hit?  Would be handy to know roughly what to aim at (not having a GPX to try it out).

I'd still be interested to know the answers to the other questions.

I've also spotted some discussion about the animated sprite sheet from fellow RR guys Ian and PJ.  It would certainly be great if GLBasic could have a built in solution for this.  I guess coming from other game orientated languages we can see the benefits GLBasic has, but the things that we found useful elsewhere that are missing here kind of stand out.  The animation is one of those things that can make your life so much easier.

I'm also hoping that you agree that functions in types is a good idea and is easy enough to implement in a future version.  I'm not asking for GLBasic to be made fully object orientated, but I think being able to wrap functions into types as methods that can access the instance's properties would be really useful to have in GLBasic.

Sorry for all the questions and requests in one of my first posts!  I'm really warming to GLBasic, especially the cross-platform compatibility.  Will try it out on my Pocket PC next :)

AndyH

Thanks Bigsofty, will take a look at that.  I guess no matter what you still have to manage ranges in the sprite id's for frames of animation so that you can use the sprite collision commands.  Would be sweet if there was that 'frame' parameter on the sprite commands to support this out of the box - for both speed and ease of use reasons.