Category:Examples

From SDL.NET

Table of contents

Looking at examples are an excellent way to learn about the SDL.NET library. This page provides information about the official examples as well as a master list of external examples.

Audio Example

Audio Example
Enlarge
Audio Example
The audio example is used to demonstrate how to use Audio in SDL.NET. It covers the basics of playing sound files and music as well as some advanced features such as setting the volume and panning effects.

Keyboard Controls

  • Space: Fadeout music
  • Up Arrow: Increase volume
  • Down Arrow: Decrease volume
  • Right Arrow: Pan music right
  • Left Arrow: Pan music left
  • Escape: Quit example

Mouse Controls

  • Primary Button: Pan music left
  • Secondary Button: Pan music right

Code

AudioExample.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/AudioExample.cs?view=markup)

See Also

Bomb Run

Screenshot of BombRun Demo
Enlarge
Screenshot of BombRun Demo

BombRun is a simple shooting game where the player moves on the bottom of the screen and shoots at the bombs falling down.

Keyboard Controls

  • Right and Left Arrows move the player from side to side
  • Up Arrow makes player "jump"
  • Space shoots a bullet.
  • Escape quits the demo

Code

  • BombRun.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/BombRun.cs?view=markup)
  • Bomb.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Bomb.cs?view=markup)
  • Bullet.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Bullet.cs?view=markup)
  • Player.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Player.cs?view=markup)
  • FireEventArgs.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/FireEventArgs.cs?view=markup)


Bounce Sprites

Bouncing Sprites
Enlarge
Bouncing Sprites
The Bounce Sprites example is used to demonstrate the power of using the Sprite class in SDL.NET. You can click on a ball to stop it from moving. Releasing the mouse button will release the ball. For a tutorial running through how this bouncing sprite example was produced, please refer to the Sprite Tutorial.

Code

  • BounceSprites.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/BounceSprites.cs?view=markup)
  • BounceSprite.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/BounceSprite.cs?view=markup)


CD Player

The CDPlayer Example
Enlarge
The CDPlayer Example

The CDPlayer example demonstrates the CD capability of SDL.NET. It can play, pause select tracks and eject the CD. It also features SDL.NET Winforms integration by using a Sprite moving on the form. You can use the mouse to grab the bouncing ball and move it around.

Code

  • CDPlayerApp.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/CDPlayer/CDPlayerApp.cs?view=markup)
  • BounceSprite.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/CDPlayer/BounceSprite.cs?view=markup)

See Also


Gears

The Gears Example
Enlarge
The Gears Example

The Gears Example uses the power of OpenGL through Tao.OpenGL and SDL.NET to display rotating gears.

Code

Gears.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Gears.cs?view=markup)

Credits


Gtk Window Example

The following is an example of using SDL.NET with a GTK# window. Click on the "Close" button to close the window.

GtkWindow Screenshot
Enlarge
GtkWindow Screenshot

The Code

GtkWindow.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/GtkWindow.cs?view=markup)

GtkWindowExample.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/GtkWindowExample.cs?view=markup)

See Also


Gtk Sprite Example

The following is an example of using SDL.NET sprites with a GTK# window. You can use the mouse to click on a circle and drag it around.

GtkSpriteExample Screenshot
Enlarge
GtkSpriteExample Screenshot

The Code

GtkSprite.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/GtkSprite.cs?view=markup)

GtkSpriteExample.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/GtkSpriteExample.cs?view=markup)

See Also


Hello World Example

The following is an extremely simple example of creating a SDL.NET window for the first time

HelloWorld Screenshot
Enlarge
HelloWorld Screenshot

The Code

HelloWorld.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/HelloWorld.cs?view=markup)

See Also


Hero Example

The following is an example of how to use the Animated Sprite class. When run, you will see a little character on the screen which you can then move around by using the arrow keys.

HeroExample Screenshot
Enlarge
HeroExample Screenshot

The Hero

This is the image that we'll be using as our hero:

Image:Hero.png

The Code

HeroExample.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/HeroExample.cs?view=markup)

See Also


Particles Example

ParticlesExample Screenshot
Enlarge
ParticlesExample Screenshot
This demo shows various features of the SDL.NET Particle engine written by Rob Loach. Gravity effects, emitters, vortexes are all displayed in this example.

Keyboard Controls

Space bar: create a particle explosion.

Mouse Controls

Moving the mouse will attract the ball and particle. The particle emitter will move as well.

Code

  • View Source (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/ParticlesExample.cs?view=markup)


Rectangles Examples

The Rectangles Example
Enlarge
The Rectangles Example

This example shows use of drawing primitives on a surface as well as basic input control. When you start the application, it draws random rectangles on the screen. When you press escape, it closes the example.


Other Primitives

SDL.NET uses SDL_gfx for drawing primitives on surfaces. It has the capabilities of drawing all sorts of primitive objects like circles, polygons, lines, etc, all with alpha transparency.

Code

The source can be found here (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Rectangles.cs?view=markup)

See Also


SharpNes

SharpNes Screenshot
Enlarge
SharpNes Screenshot
Tetris Screenshot
Enlarge
Tetris Screenshot
Elite Screenshot
Enlarge
Elite Screenshot
BombSweeper Screenshot
Enlarge
BombSweeper Screenshot

This demo is a port of the SharpNes Nintendo entertainment system (NES) emulator to SDL.NET. SharpNes was written by Jonathan Turner and ported to SDL.NET by David Hudson

Keyboard Controls

Use arrow keys to move.

Press 'Z' for button A

Press 'X' for button B

Press 'A' for Select

Press 'S' for Start

Code

SharpNes Source (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SharpNes)

See Also


Simple Game

SimpleGame Screenshot
Enlarge
SimpleGame Screenshot
This demo uses an Model-View-Controller coding structure to move a sprite around a grid. Sounds are emitted during each move. This demo is based off of a Pygame tutorial by Shandy Brown (http://sjbrown.ezide.com/games/writing-games.html)

Keyboard Controls

Use arrow keys to move red ball

Code

SimpleGame Source (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SimpleGame)

Sprite Collection Sorting

SpriteCollectionSort Screenshot
Enlarge
SpriteCollectionSort Screenshot
This demo shows how you can change the sort order of sprites in a collection. This will then blit the sprites to the surface in a different order to give them "height".

Code

SpriteCollectionSort.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/SpriteCollectionSort.cs?view=markup)

Snow Demo

SnowDemo Screenshot
Enlarge
SnowDemo Screenshot
This demo uses transparent color, alpha blending and Surface stretching. TextSprites fade in and out while snowflake Sprites fall. One of the trees at the bottom is stretched to make it appear larger.

Code

SnowDemo.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/SnowDemo.cs?view=markup)

Snowflake.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/Snowflake.cs?view=markup)

TextItem.cs (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/SmallDemos/TextItem.cs?view=markup)


Triad

Triad Screenshot
Enlarge
Triad Screenshot
Triad is a Teris-like game originally written by Michael Rosario.

Keyboard Controls

  • Right and left arrows: move the block to the right nad left.
  • Down Arrow: move block down

Code

Triad Source (http://cs-sdl.svn.sourceforge.net/viewvc/cs-sdl/trunk/SdlDotNet/examples/SdlDotNetExamples/Triad)

Official Examples

The following are the official examples that are packed with the library and are described in more detail.


Subcategories

There is 1 subcategory to this category.

E

Articles in category "Examples"

There are 12 articles in this category.

I

M

N

P

R

S

S cont.