I moved to a new URL! Check it out!

posts tagged with: csharp

Otter Updates

Otter Updates
Over the past week I've finally pushed some updates to Otter after managing to rip out the Spine animation stuff. It turns out that in order to use the Spine runtime you need a purchased copy of Spine, meaning that if I include the Spine code in Otter everyone that uses Otter would need a copy of Spine... not ideal. (I wish Spine wouldn't license their code like this.)

So now the Spine runtime for Otter lives in a separate repository. It can be used along with Otter if you import it into your solution also using Otter. After you import it you need to give it a reference to Otter (also in your solution) and then give your game project a reference to OtterSpine. Then you should be ready to roll with SpineAnimation.cs.

Other updates to otter include:

* Renamed GetClass to GetEntities on Scene
* Add Vertices graphics type
* Added Color.Mix()
* Corrected issue between game angle and graphics angles
* Fixed issue with BoxCollider constructor
* Fixed some collision bugs
* Added shortcut of Left-Alt in Debugger to hide debugger (useful for screenshots)
* Minor updates to Particle
* Added LerpColor to Util
* Slight changes to Vector2

If there's any bugs or horrific things broken then let me know in the Otter forums!

Dev Log: Some Shaders

Dev Log: Some Shaders
One of the things I miss about working in FlashPunk and working with a bunch of bitmaps and blitting to the screen is the super easy color overlay blending. FlashPunk had an Image blending mode called Tint and it could be used in place of Multiply and it is amazing for doing effects like fading an entire sprite to a specific color. The world of rendering quads and triangles I don't have such a luxury, but I do have shaders.

I've been working on the building islands animation, and here's a really fast version of it:

Image


At the end of it when the island pops out it's silhouetted with solid white. The white fades to cyan, and also fades back to the normal art at the same time. To get this effect I used a simple shader to handle a color overlay.
uniform sampler2D texture;
uniform vec4 overlayColor;

void main() {
vec4 pixcol = texture2D(texture, gl_TexCoord[0].xy);
vec4 outcol = mix(pixcol, overlayColor, overlayColor.a);
outcol.a = pixcol.a;
gl_FragColor = outcol;
}
I also use this code for enemies as well. When they get hit they turn red for a brief moment. I use code in the C# end to determine the color and intensity of the overlay and pass it along to the shader.
var overlay = Util.ScaleClamp(Combatant.Stun, 0, Combatant.StunMax, 0, 1);
var color = new Color(1, 0.2f, 0.1f, overlay);

ImageSpineAnim.Shader.SetParameter("overlayColor", color);
Soon I'll probably make some sort of system that allows me to easily add a bunch of color overlays to the shader and automatically figure out the final color for the shader to use. I'll probably also use the shader for a bunch of different effects down the road.

Dev Log: Otter Spine Animations

Dev Log: Otter Spine Animations
Today is a very awesome day, for I finally got Spine animations running in Otter! I only have the super basic stuff right now, but I'm hoping to expand the support as I tinker around with Otter and my next game.

Image


This is a quick test of the test animation that comes with Spine. Right now a skeleton can be loaded up, and play its animations in the most simple way. The next steps will be getting all of the cool spine functionality in and running, like being able to manipulate bones and mix animations and all that kinda stuff.

This hasn't been pushed to Otter yet, and probably won't be for at least a few more days as I test it out and hopefully work out any show stopping bugs that might appear.

While making the Otter implementation of Spine I made great use of the Spine csharp runtime which I just dragged and dropped into Otter, and I also referenced the XNA runtime, along with C#Punk's implementation of a SpineAnimation graphic type.

Flippy Flop Source

Flippy Flop Source
Yesterday I made a quick game called Flippy Flop using Otter. The whole thing only took me two hours or so, and the end result ended up being a relatively clean coded game.

I decided to add the Flippy Flop source code to the Otter source repository on BitBucket in the Examples folder. So now when you grab Otter you'll also get the source for the Otter Pong Game, and the amazing Flippy Flop.

Flippy Flop makes use of the EventRouter included in Otter. The EventRouter was originally authored by some smart Phoenix locals, and is used a lot in their Unity projects. Since it was just a C# implementation I grabbed and it stuck it in Otter. The EventRouter is all about following the Observer pattern. It can be a little weird to use at first, but I'm beginning to see the appeal of it.

(Disclaimer: There may be some bugs in the source for FlippyFlop. I didn't really check it over for memory leaks, which can easily pop up when using an Event system. If you don't make sure you're unsubscribing from events when objects are removed, or clearing the event router, you might find yourself in memory leak city.)

If you have any questions about Otter, or the source code of the game, check out the Otter forums or leave a comment below.

Dev Log: Cooldown Drawing

Dev Log: Cooldown Drawing
Been a little bit sickly feeling these last couple days so I haven't been too active on the dev side of things. It's been super tough because I've been laying down the ground work for these systems that I want to be part of the game, and since I have no idea what I'm doing progress is a little bit slower than I'd like it to be. Maybe I should start working on a platformer on the side so I can at least dip my toes into familiar space every once in awhile.

One of the tasks on my to do list was to figure out how to draw those cool spell cool down graphics you always see in action RPG, and a lot of RTS games. When you have a spell or ability represented as an icon on the screen, one of the most common ways to show it's cool down before you can use it again is an overlay that slowly erodes with a radial wipe.

Image


There are a lot of different ways to do this, but eventually I went with this simple method using a triangle fan. I had written down an idea of using geometry before, but this implementation is waaay simpler than the madness I wrote in my notebook with using four quads or a triangle fan with way too many points. Here's the entire implementation, also available right now to use in Otter as SquareClock.
public class SquareClock : Image {

VertexArray vertices;

/// <summary>
/// Determines the fill of the clock.
/// </summary>
public float Fill {
set {
fill = Util.Clamp(value, 0, 1);
NeedsUpdate = true;
}
get {
return fill;
}
}
float fill = 1;

public SquareClock(int size, Color color) {
Width = size;
Height = size;

Color = color;

NeedsUpdate = true;
UpdateClock();
}

void UpdateClock() {
if (!NeedsUpdate) return;


if (fill == 1) {
//draw box
vertices = new VertexArray(PrimitiveType.Quads);
Append(vertices, 0, 0);
Append(vertices, Width, 0);
Append(vertices, Width, Height);
Append(vertices, 0, Height);
}
else {

vertices = new VertexArray(PrimitiveType.TrianglesFan);

if (fill > 0) {
//draw center
Append(vertices, HalfWidth, HalfHeight);
//draw middle top
Append(vertices, HalfWidth, 0);
if (fill >= 0.125f) {
//draw left top
Append(vertices, 0, 0);
}
if (fill >= 0.375f) {
//draw left bottom
Append(vertices, 0, Height);
}
if (fill >= 0.625f) {
//draw right bottom
Append(vertices, Width, Height);
}
if (fill >= 0.875f) {
//draw right top
Append(vertices, Width, 0);
}

// get vector of angle
var v = new Vector2(Util.PolarX(FillAngle, HalfWidth), Util.PolarY(FillAngle, HalfHeight));
// adjust length of vector to meet square
var l = (float)Math.Max(Math.Abs(v.X), Math.Abs(v.Y));
if (l <= HalfWidth) {
v.X /= l;
v.Y /= l;
}
// append the vector
Append(vertices, HalfWidth + (float)v.X * HalfWidth, HalfHeight + (float)v.Y * HalfHeight);

}
}

DrawableSource = vertices;

NeedsUpdate = false;
}

public float FillAngle {
get { return (fill * 360) + 90; }
}

void Append(VertexArray v, float x, float y) {
v.Append(x, y, Color);

}
public override void Update() {
base.Update();
UpdateClock();
}

}
The downside with this implementation is that I'm pretty limited as to where I can draw the original angle from. Since I've made this into a Graphic type in Otter I can actually flip it, scale it, and rotate it in any way I want, but I won't be able to change where the start and ending angle end up. That's okay for now since I won't be needing that functionality myself, but maybe if I have some time I can implement a more advanced version of it soon.

Otter Updates

Otter Updates
As I work away at my next project I'm also pushing some changes to Otter, which is my 2d game making framework that runs on SFML 2 and C#.

I didn't get to make many updates during the holidays, but now I'm back in the swing of things. Here's some of the latest stuff that's been updated:

Better mouse locking.
You can now lock the mouse to the center of the screen and use the delta mouse positions to track the cursor position. If you use this option you can still just use Input.MouseX and Input.MouseY normally.

Debugger fixes
The mouse unlocks when the debugger is opened, and I think I fixed some bugs with hiding and showing the debugger. The log will now look nicer when using Log to print multiple lines. Added quit to do the same thing as exit.

Session construtor public
Just in case you want to extend session, but I'm not sure if I want to keep it this way.

Updated SFML dlls
I found that someone made new builds of SFML so I was able to update the dll files to fix some bugs (like only being able to click on the title bar to gain focus)

Image shake property (still weird now though)
Images can now shake but this doesn't make too much sense because the shake is updated at every render call (instead of update)

Rich text documentation
Added some more comments to rich text

More Rand functions
Rand.Float() can use a Range now, and there's a method for generating a point inside a circle.

Util additions
Added some stuff to Util that may or may not be useful.

AutoTimer added
A utility component class that might be useful for some stuff.

Linux, OS X stuff
Merged in the .csproj file from Ventero for hopefully Linux and OS X support with Mono? I'm not totally sure how this stuff works but Linux and OS X should be easier to build with this new .csproj file and Mono.