I moved to a new URL! Check it out!

posts filed under: otter

Otter Example: Text

Otter Example: Text
The last Otter example I was able to jam out before leaving for PAX was all about Text and RichText. Text seems to just be insanely difficult and time consuming to implement, so making it really easy for users of Otter was a big goal of mine. For most simple cases of using Text, Otter should accomplish that goal!

Here's a quick example of just some normal text using some simple effects.
  class Program {
static void Main(string[] args) {
// Create a Game.
var game = new Game("Text Example");

// Create a Scene.
var scene = new Scene();

// Create a Text object using the default font with size 16.
var text1 = new Text("Just some basic text.", 16);
// Position the Text.
text1.SetPosition(20, 20);
// Add it to the Scene's Graphic list for rendering.
scene.AddGraphic(text1);

// Create a Text object using the deafult font and a size of 32.
var text2 = new Text("Bigger text!", 32);
// Position the Text.
text2.SetPosition(20, 50);
// Add it for rendering.
scene.AddGraphic(text2);

// Create a Text object using the font yardsale.ttf and a size of 40.
var text3 = new Text("Using a font", "yardsale.ttf", 40);
// Position the Text.
text3.SetPosition(20, 120);
// Add it for rendering.
scene.AddGraphic(text3);

// Create a Text object using the font yardsale.ttf and a size of 40.
var text4 = new Text("Using a shadow!", "yardsale.ttf", 40);
// Set the shadow color of the Text.
text4.ShadowColor = Color.Red;
// Position the Shadow.
text4.ShadowX = 1;
text4.ShadowY = 3;
// Position the Text.
text4.SetPosition(20, 170);
// Add it for rendering.
scene.AddGraphic(text4);

// Create a Text object using the font yardsale.ttf and a size of 40.
var text5 = new Text("Using an outline!", "yardsale.ttf", 40);
// Set the outline color of the Text.
text5.OutlineColor = Color.Green;
// Set the thickness of the outline.
text5.OutlineThickness = 3;
// Position the Text.
text5.SetPosition(20, 220);
// Add it for rendering.
scene.AddGraphic(text5);

// Start the Game using the created Scene.
game.Start(scene);
}
}
Image


For doing text beyond that Otter has a RichText graphic object that can be used. This allows for some more advanced things such as limited text boundaries, word wrapping, text align, effects applied to specific characters, animated text, and more, but RichText is also less efficient for rendering larger blocks of text.

For the full example head on over to the Otter example.

Image

Otter Example: More Collisions

Otter Example: More Collisions
Hot of the presses with a new Otter example! This example goes over more of the collider types that can be used in Otter. In total Otter has a Box, Circle, Grid, Polygon, Pixel, Point, and Line collider, and this example will cover all of them except for the Pixel collider (because that one should be used very sparingly anyway.)

Here's a quick preview of the code that can be found in the example:
class PolygonTest : Entity {

PolygonCollider polygonCollider;

public PolygonTest(float x, float y) : base(x, y) {
// Create a PolygonCollider and give it some Vector2 points.
polygonCollider = new PolygonCollider(
new Vector2(0, 0),
new Vector2(80, -10),
new Vector2(30, 90),
new Vector2(-5, 15),
new Vector2(0, 5)
);

// Add the Walls tag (since this isn't in the constructor.)
polygonCollider.AddTag(Tags.Walls);

// Set the rotation to a random angle.
polygonCollider.Rotation = Rand.Angle;

// Add the Collider.
AddCollider(polygonCollider);
// Center the origin of the Collider.
polygonCollider.CenterOrigin();
}

public override void Render() {
base.Render();

// Render the Collider for debug purposes.
polygonCollider.Render();
}
}
The full example places a bunch of colliders in a scene with a moving object to test collisions with.

Image


A lot more examples are on the way!

Otter Example: Player Sessions

Otter Example: Player Sessions
Things have been pretty hectic for me for the past week so unfortunately all I've really had time to do is more Otter examples.

Image


A Session in Otter is a cool way to keep track of a player playing your game. You can set the controls in a session, and also keep track of other data such as high scores, levels unlocked, whatever else. Sessions also have an easy way to export data in a semi-encrypted format to prevent most players from tampering with it.

The full example is just a click away and you should totally check it out!

Otter Example: Basic Collision

Otter Example: Basic Collision
Fresh out of the oven is another example for Otter, the 2d game making framework based on SFML.net. The new example covers basic collision detection and response.

Image


On the examples page I've listed out all of the examples I want to cover in the next few weeks. I'm going to try to keep working on posting an example every few days or so, but I have some upcoming travel that might make that difficult. We'll see!

Oh and so many people are sending me this image so I might as well post it here:

Image

Otter Example: Spritemap Animations

Otter Example: Spritemap Animations
I want to keep the Otter example train rolling until I manage to flesh out enough examples to cover all the basics of making a game. The newest example covers animating sprites using a quick example sprite sheet from the Spriter's Resource.

The example with all of the code and required image is available right here.

Image


Also a reminder: if you're using Otter actively make sure to stop by the forums, or sign up for the relatively new Otter Slack Team. There's actually quite a bit of activity happening in the Slack, and recently one of the Otter community members posted a new GUI suite of components to use in your Otter made games!

Otter Example: Loading Images

Otter Example: Loading Images
A new example for Otter is now available! The new example covers loading images into a game. This example assumes that you have a decent understanding of C# already as it uses some stuff like local variables and extending classes and all that cool stuff.

The example also covers using Visual Studio to manage external resources. The most simple way of using a small amount of resources is to have Visual Studio copy the files into the bin directory. So check out the example for all those details!