I moved to a new URL! Check it out!

posts tagged with: csharp

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!

Otter Example: Input

Otter Example: Input
I just posted one more quick example for using Otter!

The Input and Basic Interaction example deals with using the Input class to check for keyboard keys being pressed and held down, and responding to that by moving an Entity around the screen. This is the first example to really get into potential video game looking code.

Also as a side note I started an Otter slack team that is open invite to anyone that wants to chat in real time with other Otter developers. Hopefully we can get a solid crew of folks in there to push the framework foward.

Otter Examples

Otter Examples
Making use of Couch CMS I've finally gotten around to making an example page for Otter!

The first three examples are a very basic introduction to setting up Otter and using it to start putting stuff on the screen. I plan on adding examples every so often since the videos I made a long time ago are now sort of outdated. Otter continues to grow and evolve over time so it's tough to keep a solid set of examples to go with it. For example the controller class has gone through some changes over the past year which makes a lot of the tutorials written for it outdated. Hopefully I can keep examples up to date though using Couch.

Just a little bit about CouchCMS too: this is one of the coolest things I've used in my web dev days. I really wish I had tried it earlier because I think it's going to forever replace my need to write my own CMS every time I make a new site for myself. It really seems to cover everything and it feels way easier to customize than something like Wordpress or Tumblr. Sure it might not be as powerful as those right off the bat, but I think Couch really fits my style more. It also comes with an awesome file uploader and browser which makes image and file uploading a breeze. It makes everything a breeze! You should definitely check it out if you do web work of any kind.

Otter Updates

Otter Updates
Some quick Otter updates!

* OnAdded() timing has been changed for Entities. When an Entity is added to a Scene the OnAdded() method is now called after the Entity has updated its component lists. This is so that a component can register with the Entity's OnAdd method before the Entity is added to the Scene.

* Added GetTopEntity() and GetBottomEntity(). These methods allow you to pass in a bunch of Entities and find the top most and bottom most entity in the rendering.

* Added GetComponent() shortcut methods to Component.

* Added CollideEntities<T> method that will return a list of a specific type of Entity.

* Possible graphics changes. I want to explore the possibility of reworking the rendering system to allow for multiple transformations to be applied to graphics. This would possibly allow easier parent to child relationship transformations and more. Mostly because I noticed when working on games that I want to have multiple scales, rotations, and translations applied to graphics at times, and it would be nice if Otter had built in support for it.

That's all for now!

Image

The Future of Otter

The Future of Otter
Time for some thoughts!

I have this game engine called Otter. It's heavily inspired and influenced by Flashpunk which I used for a number of years for a number of games including Offspring Fling.

I really like using Otter, and it was a lot of fun developing it, but lately I'm not feeling super sure if I can depend on it for the future. Otter really fits my coding style, and I've learned a lot making it, and I feel like it can always be improved (often times I have to resist the urge to start a new version of it that would improve on the core of it now that I know way more about .net, SFML, and openGL,) but I'm not sure how worth it is to keep using.

Unity is gobbling up a lot of game devs these days. Everyone and their grandma is using Unity to develop games. I don't have anything against Unity, but I have a hard time leaving my fate to a tool that is essentially a black box. I have a lot of friends that use it, and sometimes their stories about core Unity bugs disrupting their entire project can give me nightmares. Being at the mercy of a crazy Unity bug that wont be addressed for a few versions seems incredibly stressful... so I'm not totally sold on jumping ship to the Unity train.

I think the core hesitation I have with Otter lately is its dependency on SFML.Net. SFML has had a lot advancements lately thanks to the recently formed core SFML team, but I think SFML.Net and the C bindings are going to be left by the wayside as they start making progress on the core C++ version. There's just not enough people using SFML.Net, and often times I feel very isolated when trying to solve weird issues since the community is so tiny.

So maybe one of my options is to go to XNA/Monogame, but that isn't a perfect scenario either. Unity's main draw to me right now is the whole built in editor and inspector thing, and XNA/Monogame doesn't leave me in any better of a position than SFML in that regard. I don't have any editors for Otter, and once I step outside the realm of pixel art there's absolutely zero good solutions out there for editing content (for something like a platformer, for example.) There are a couple of spun up editor projects out there, but they are barely useable and have way too many bugs for any project outside of the scope of a 48 hour game jam.

Another option is Haxe, but honestly I'd do anything to stick with the world of .net and C# for as long as possible. I love C# and it's amazing, and I don't want to go back to anything that resembles actionscript.

I'm just sort of using this blog post to think outloud really. I really like Unity's editor aspect lately, but their 2d support still seems really dumb... and relying on a third party tool is something that I'd rather not do (I've been scarred though my years of using Klik & Play and all of it's successors.) Maybe I can port Otter to XNA/Monogame and that would be a good solution, but I'm not exactly looking forward to spending a month or so doing that. What I was really hoping for was for someone to join up with me for Otter development but unfortunately I don't think Otter is cool enough for that to happen. Really what I probably need is more info about how to get started using Otter. The little info I've put out there has now become outdated, so starting up with Otter can be pretty though for the average person.

All in all I think I'm going to keep using Otter for the time being, and I think the most realistic scenario is a port of the internals to something else. The XNA/Monogame route seems very tempting, but I know there are a number of problems with that that need to be solved beforehand. There were some specific reasons I went with SFML over XNA and I'm not sure how I'm going to get around some of the issues there. Maybe I can cut out SFML and just go straight into openGL or something... but then I know things like text rendering is going to be an even bigger nightmare than it already is now.

There's never a perfect solution for this kinda thing! If only I had a little bit better of a programmer brain I could make Otter into the perfect portable engine for different platforms, and I'd make a sweet editor to go along with it... oh well! Really I have no idea what to do right now, but that's par for the course. Guess I'll just keeping working on Sky Sisters and a couple of other projects I have spun up and see what happens.

Otter Surface Example

Otter Surface Example
Just a quick post going over how I usually use Surfaces in Otter. A surface is basically a render texture, or render target. The idea of calling it a surface mostly comes from Game Maker.

By default Otter will render all of the graphics to the main surface. However you can make your own surfaces and use them in various ways. The main point of this quick example is to show how to separate HUD elements and gameplay onto different surfaces. The big advantage of doing this is you can now freely rotate and zoom the camera and the HUD will be unaffected.

Alright let's check out the codes!
class Program {
static void Main(string[] args) {
// Create a new game to play.
var game = new Game();

// Set the scroll of the surfaces to 0 so they never scroll on the camera.
Global.SurfaceGameplay.Scroll = 0;
Global.SurfaceHud.Scroll = 0;

// Start the game with a new GameScene.
game.Start(new GameScene(1000, 1000));

}
}

class GridBackground : Entity {
public GridBackground() : base() {
Layer = 10;
Surface = Global.SurfaceGameplay;
}

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

// Just render a simple grid background so when the camera scrolls we can see it.
AddGraphic(new Grid(Scene.Width, Scene.Height, 40, 40, Color.Cyan));
Graphic.Alpha = 0.4f;
}
}

class Player : Entity {
public Player(float x, float y) : base(x, y) {
// Add a basic red box for the graphic.
AddGraphic(Image.CreateRectangle(20, 20, Color.Red));
Graphic.CenterOrigin();

// Assign this entity to render to Global.SurfaceGameplay instead of the default game surface.
Surface = Global.SurfaceGameplay;

// Set up a collider for movement.
var collider = AddCollider(new BoxCollider(20, 20));

// Set up the rest of the movement stuff.
var axis = AddComponent(Axis.CreateWASD());
var movement = AddComponent(new BasicMovement(400, 400, 30));
movement.Axis = axis;
movement.Collider = collider;
}
}

class PlayerHud : Entity {
public PlayerHud() : base() {
// Basic hud test with just some text.
AddGraphic(new Text("This is the HUD!", 20));

Surface = Global.SurfaceHud;
}
}

class GameScene : Scene {
public GameScene(int width, int height) : base(width, height) {
// Add the entities to the scene when the scene is created.
Add(new Player(HalfWidth, HalfHeight));
Add(new GridBackground());
Add(new PlayerHud());
}

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

// Set the scene's camera to follow the player.
var player = GetEntity<Player>();
CenterCamera(player.X, player.Y);

// Set the surface's camera to follow the scene's camera.
Global.SurfaceGameplay.CameraX = CameraX;
Global.SurfaceGameplay.CameraY = CameraY;

// Zoom the surface up and down with the arrow keys.
if (Input.KeyDown(Key.Down)) {
Global.SurfaceGameplay.CameraZoom -= 0.005f;
}
if (Input.KeyDown(Key.Up)) {
Global.SurfaceGameplay.CameraZoom += 0.005f;
}
}

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

// Render the surfaces.
Draw.Graphic(Global.SurfaceGameplay);
Draw.Graphic(Global.SurfaceHud);
}
}

class Global {
// Keep global references to the surfaces used for rendering the game.
public static Surface SurfaceHud = new Surface(640, 480);
public static Surface SurfaceGameplay = new Surface(640, 480, Color.Gray);
}
The full version is available on pastie.

I have a simple player class, and background class which both render to the surface designated for gameplay. Then the player HUD class is assigned to render to the hud surface. The scene will then take care of rendering both of those surfaces to the game's main surface. I render in the scene's Render method because that will be the very last thing that renders in the frame.

I know some people have been having trouble understanding surfaces fully and how to use them so I hope this example helps. Surfaces can be really powerful especially when you start getting into shaders and one of my main goals for Otter was to make using surfaces as painless as possible.