Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

TurboSprite

2010-07-15

TurboSprite is a software driven (GDI+) sprite engine written by Dion Kurczek in C#. The reason that I’m picking this up, is that it shows (like I have mentioned before) the amazing capabilities and performance of the GDI+ library in .NET. TurboSprite provides a sprite container, bitmap sprites, vector sprites and collision detection.

To be able to use TurboSprite, download and compile it, add the components to your toolbox. Then, add a surface and an engine to a form. Note that you have two engines. One is called SpriteEngine and another is called SpriteEngineDestination. Use the SpriteEngineDestination object, because it extends the SpriteEngine class with the ability to move sprites. You might want to set a few properties to connect the engine to the surface, to tell the engine if you want collision detection and so on. Collision detection is a reasonable cause for using a sprite engine. I use the AutoBlank feature of the surface.

About the moving of the sprites, you can acquire the sprite mover using the GetMover function for the engine (if you use the SpriteEngineDestination), and set the X and Y speed of a sprite. Or you can do as I do in this example below. That is, just set a speed and a destination position. The destination position determines the sprite movement direction.

This code does two thinks (written in the Show event of a regular form). The first line activates the sprite engine so that sprites will move. The rest of the code initializes one vector sprite.

'When the form is loaded, activate the surface
SpriteSurface1.Active = True

'Create a space ship. These points makes a ship.
Dim S As New SCG.TurboSprite.PolygonSprite(0, -10, 5, 10, 0, 5, -5, 10)

'Tell the sprite to rotate.
S.Spin = SCG.TurboSprite.SpinType.Clockwise
S.SpinSpeed = 3

'Start position.
S.Position = New Point(30, 30)

'Add the sprite to the engine, and acquire the sprite mover from the engine.
SpriteEngineDestination1.AddSprite(S)
Dim Mover As SCG.TurboSprite.DestinationMover = SpriteEngineDestination1.GetMover(S)

'Tell the mover about speed and direction.
Mover.Speed = 5
Mover.Destination = New Point(50, 40)

'Tell the mover that the destination really isn't a destination,
'it's just used as a direction.
Mover.StopAtDestination = False

This is the sprite:

Download the engine from the Code Project web site.

Categories: Visual Basic 9

Tags: 2D game

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips