This project is read-only.

Sprites and Objects

The most common way to display images on a GameObject is through the use of Sprites. A Sprite defines a single graphic file (Image) and frame bounds (Rectangle) within that image. This allows a single image file to serve as a "sprite sheet" containing multiple sprite images and/or multiple image frames of a single sprite.

Each GameObject contains a Sprites collection. Any sprite instances added to this collection will be updated and rendered by the GameObject. Each Sprite should only belong to one GameObject.Sprites collection at a time, however, individual Sprite instances can all point to the same asset file.

Sprites offer a PositionOffset property which allow you to arrange them on a game object, and this accounts for each object requiring a unique sprite instance.

There is no limit to the number of sprites which can be added to a single game object, however, performance should be considered due to the extra draw operations, especially if scaling or rotation are used.

Animated Sprites

The AnimatedSprite class is a sprite with multiple Frames. The Frames collection should have each frame added in order of animation sequence. The AnimationRate property can be used to determine how long it takes to play one complete cycle of the animation. In the example below, the four frames of animation take 1/4 of a second to complete, therefore the animation is playing at 16 frames per second.

Example of PlayerChopper class loading an AnimatedSprite
    Protected Overrides Sub OnLoad(e As GdiGaming.GameEngineEventArgs)
        Dim chopperSprite As New AnimatedSprite
        chopperSprite.SpriteSheet = "AirVehicles"
        chopperSprite.AnimationRate = 0.25F
        chopperSprite.AddFramesHV(1, 4, 48, 48)
        chopperSprite.Name = "Chopper"
    End Sub

Last edited Dec 30, 2011 at 1:39 AM by ReedKimble, version 3


No comments yet.