Help with Sprites and Transparency

Drewpeu

Member
Licensed User
Hi Erel,

I have just purchased basic4ppc, up to this point I have been a GLBasic
person as it can compile for multiple Operating Systems.

I have been trying to get my head around Sprites and Transparency in
basic4ppc as they are used in a different way!

GLBasic:
LOADSPRITE "ship.bmp",0
LOADSPRITE "shot.bmp",1
LOADSPRITE "buga.bmp",2
LOADSPRITE "boom.bmp",3



The sprite's are referred to numerically or given names.

// Player
INC playerx, MOUSEAXIS(0)
playerx = MAX(MIN(playerx,600),32)
SPRITE 0, playerx, 456 //sets the ship.bmp position
SHOWSCREEN


The ship.bmp has a background colour of RGB(255,0,128) which is transparent
the sprites in basci4ppc also have transparency bur an image does no seem to
have thia capabillity, the image button is no use for this either as its
transparency is the same as the Form or Panel background colour?


// Invaders
TYPE FOE
x
y
speed = 3
amour = 4
ENDTYPE

LOCAL bugs[] AS FOE



FOREACH bug IN bugs[] / draw the invaders on the screen and animate
INC bug.x, bug.speed
IF bug.x<0 OR bug.x>640
bug.speed = - bug.speed
INC bug.y, 32
ENDIF
NEXT




How would I handle all this in basic4ppc, I will end up with six rows of
invaders, each row will have a score value, top will have the highest score
so I need to know which sprite has been destroyed.

Can I put the sprites in a structure or an Array?

I am not asking you to do the programming for me but I would like more info
on how to controll the sprites within the game.

Regards,
Andrew.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
First I recommend you to go over some Sprites examples:
You can find one under c:\Program Files\Anywhere Software\Basic4ppc Desktop\Samples
And here: http://www.b4x.com/forum/code-samples-tips/1595-walking-character-using-sprite-library.html

You can use the Control keyword to work with a group of sprites or any other objects.
For example:
B4X:
For i = 1 to 10
 Control("Sprite" & i, Sprite).X = ...
Next
See this tutorial for more information: http://www.b4x.com/forum/tutorials/907-runtime-controls-manipulation.html

BTW, you can also consider using the ImageLib library and handle all the drawing without the Sprite library. This will give you more control.
 
Top