PDA

View Full Version : I need some advice to get started with simple 2D-game



ReneMiner
22-10-2012, 11:33
I hope this is the right section of this forum to ask.

I discovered thinBasic yesterday, early in the morning by searching for some new, up-to-date Basic-language and I think I should give it a try.
(I used vb from 3.0 to 6.0, purebasic, qb and all kinds of basic languages that was available in the old days for vc20,c64,plus4, amiga, atari xl+xe+st.
Now you can imagine the amount of my basic-knowledge (vb.net I do not like, I did Try- but it did not Catch me- especially the ms-vb-online-help is a nerving pain to me- I'm stuck to clearly arranged offline-helpfiles)

I never learned any other programming-language than basic. (html and similar I won't call coding-language, in C (++/#) and java I loose overview to fast because of the many objects that are generated automatically)

Now I've read a lot of the included help-file, tried many tutorials and browsed this forum for many hours as well, but I did not find an answer.
To get familiar with the use of thinBasic I want to port a simple 2d-game, that I wrote in another basic language, to thinBasic now. It's a simple tile-game with usual square 2D-sprites.
Now I'm up to use an ImageList to store all of my about 250 little sprites and draw them onto the canvas but I don't find out how I can draw bitmaps that are stored in ImageList at certain position of a window (Dialog) , Canvas or whatever.
It has to be possible somehow (I saw it in the Mushroom-Game).
Now my question is: Can I use Images stored in Imagelist to draw them transparent (i.e. RGB(255,0,255) shall be transparent) onto the Canvas?
Is there some example-code / template for use of 2D-sprites or do I have to use just TBGL as a 2D-engine?


And by the way: thinBasic-Help-Manual (*.chm-version) tells about FreeImage-Library- but it's not available in my tB-Version 1.8.9.0. (No .dll, nor samples either)

EDIT: OK, I've found out! I'm gonna use TBGL now instead of an ImageList (found the tbgl-specific Help in User-Help finally - since the "TBGL Help File"-Button in thinBasic Help manual, section "thinBasic Modules > TBGL (Graphic Library)" does not work )
- Forums-Moderator might erase this question-

peter
22-10-2012, 12:54
Hi,

Of course, it is possible to make transparent sprites. You have to take the Window Api or TBGL_sprites.


This Mushroom game used the Window Api und the TBGL_CreateWindow .
But now, you can not use both together. You have to find something other.


I work at an Api-library and have somewhat success.
Soon, I will give a demo about this Api work.


Anyway, I am glad to see a Basic game programmer.

Petr Schreiber
22-10-2012, 13:21
Welcome!,

TBGL should work fine for you. Make sure you checkout the sprite samples in:
thinBasic/SampleScripts/TBGL/Sprites/

The help file for TBGL can be reached in thinAir this way from menu:

Click on Help
Click on User help
Click on thinBasic_TBGL


Or when you use F1 key on any written TBGL command in the editor.


Petr

ReneMiner
22-10-2012, 14:35
OK, thanks. Still one more question:

Is it a good idea to load them sprites as Textures into memory and create clones then with TBGL_CreateSprite()-method?
since I do not know how many sprites of which kind are used for a level in the game in advance?
Or can I draw the same, once loaded sprite (like a Wall-Brick) as often as it's needed into the window?

Michael Clease
22-10-2012, 14:49
I would draw a screen full of sprites and then point the sprites at a new texture or new position on a sprite sheet, this will also have the advantage that each tile is under your complete control so you can scale, rotate, flip or even make it invisible.


TBGL_SpriteSetTexCoord ( spriteID , frameNo, x1, y1, x2, y2 )
TBGL_SpriteSetTexFrame ( spriteID , frameNo )
TBGL_SpriteSetTexture ( spriteID , textureID )


Mike C.

ReneMiner
22-10-2012, 16:26
Good idea, I'll try that - seems to be memory-saving since I don't have a BMP-file-header for each and every little picture then.

I just wonder, if I can define a user-type like this:

Type myType
X(10) as Long ' array in Type? Help does not show this in example - or do I have to use these [ ] brackets?
End Type

dim myThing as myType

does myThing have now .X(0) to .X(9), or .X(1) to .X(10), or .X(0) to .X(10)?

Michael Clease
22-10-2012, 17:01
Type mytype
x(10) As Long
y(10) As Long
z(10) As Long
End Type


Dim mm As mytype

mm.x(1) = 100
mm.y(1) = 200
mm.z(1) = 300


Yes you can (as above) and all thinBasic arrays are not from 0 but from 1, in the example it would be 1 -10.


Mike C.

ReneMiner
22-10-2012, 17:13
Thanks a lot :D