Nez: free, open source 2D framework

Thanks for the heads up on SpriteBlinkEffect. I have been trying to use it, but I have been running into issues. For reference, I essentially have the Nez (Portable) and Nez.PipelineImporter projects imported as shown from the youtube tutorial. Anyway, I tried using the SpriteBlinkEffect, but it caused a runtime error:

DirectoryNotFoundException: Could not find a part of the path ‘C:\MyProject\MyProject\bin\DesktopGL\AnyCPU\Debug\Content\nez\effects\SpriteBlinkEffect.mgfxo’.

I tried pasting the mgfxo file into the correct place (I got it from the Nez repo at Nez/DefaultContent), but then I got the following error:

‘This MGFX effect is for an older release of MonoGame and needs to be rebuilt.’

So instead I tried to build the files myself, but here I am not exactly sure what to do. I copied the .fx files into my Content folder (from the Nez repo in DefaultContentSource). I imported the nez/effects folder into my MonoGame Pipeline tool, and built it. When building the .fx files, I used the “Effect Importer - MonoGame” Importer and “Effect - Monogame” Processor. It built successfully, but I looked in the bin\DesktopGL\AnyCPU\Debug\Content\nez\effects\ and it has .xnb files instead of .mtfxo files. When I try to run it, I get a file not found exception again (because it is looking for SpriteBlinkEffect.mtfxo instead of SpriteBlinkEffect.xnb)

What is the correct process to create the SpriteBlinkEffect.mtfxo file in the Monogame Pipeline tool? What is the difference between .fx, .fxb, .xnb, .mtfxo files. Which should I use, and which importer and processors in the MonoGame Pipeline tool should I use to create the correct files? Thanks in advanced.

If you are using MG 3.6 you will need to rebuild all the effects. When you rebuild them they must be put in the exact location as in the repo with the same file name.

Which files should I be building? When I try to build the .fx files, the result is an .xnb. When I try to build mtfxo files, it does not work saying:“Bad token CppNet.Token”. Are the mtfxo files the result of building other files, or the files I need to build?

EDIT: I have learned more about the issue, it seems that building an .fx file with the Monogame Pipeline tool results ina .xnb file, which is more information than a .mtfxo file. I am still unsure if it is possible to use the Monogame Pipeline tool to get a .mtfxo , but I am going to try using 2MGFX for now. http://www.monogame.net/documentation/2/?page=2MGFX

2MGFX will do the trick. All the compiled effects included with Nez are compiled outside the Pipeline Tool using 2MGFX directly.

Does anyone know how to use Nez to create procedurally generated tile maps? Is this possible by leveraging the existing Nez.Tiled APIs?

There is nothing stopping you from using the Tiled API to make procedural maps. There is an example in the Samples repo that does the opposite: destroys tiles procedurally. You can achieve procedural generation by doing it just like that sample except fill in tile data rather than remove it.

Hi there, is there any batching functionality for the ‘mesh’ components?

Mesh doesn’t do any dynamic batching out of the box. You can, however, just use a single Mesh for all of your needs by manually assigning the verts/UVs.

1 Like

@prime31 Thanks for the reply. Also, is there any drag and drop functionality for the UI, maybe like in Unity? :stuck_out_tongue:

There is no generic drag and drop but you can extend the UI any way you want. See the slider component for an example.

Thank you @prime31!

One more question though :smile:… what would be the most appropriate way to have a sprite component that can be ‘skewed’? The usage would be for a game in which the arts are made in 4 directions, but the characters can look anywhere, so instead of just ‘snapping’ to one of the closest cardinal directions, I’m planning to ‘snap’ only the texture but do a little bit of ‘skewing’ on the vertices, so the rotations look a bit more natural. My idea is to store the ‘rotation’ internally in order to properly position weapons and such, but I’d like to have a component that plays well with the others, like preserves batching if possible, etc.

Btw, I’ve updated the Samples to work with the latest API (few fixes findObjectOfType), gonna PR soon.

The Batcher has a draw method that takes in skew values. You can just use that to do your drawing.

1 Like

Hi @prime31, sorry to annoy you again and thanks for your last replies… I’d like to know if there’s a simple way to translate an entity in local space, at the moment I’m having to grab the transform matrix and manually multiply its members by a vector, so I guess I’m missing something here; can’t be that hard I guess :innocent:

EDIT: Also, I noticed that when I translate stuff based on their rotation, I get angle ‘snapping’ because apparently entity positions are rounded to integers, is there a way to prevent that? EDIT2: It’s Transform.shouldRound

C’mon guys, is there no API similar to say entity.translateLocal(Vector2.UnitY) or maybe a way to do say entity.position += entity.up to move an entity ‘forward’?

The Transform class lets you modify all properties in local and global spaces. Just use the methods/props prefixed with local.

I have no idea what you are trying to accomplish with something like entity.position += entity.up. What does that even mean? Moving a position by a direction doesnt make any sense. You have to modify a position by adding another position.

Well, entity.up would be the normalized direction of the entity Y+ in world coordinates. So to move an entity forward, say a bullet that has an arbitrary rotation and you want to translate forwards, you could use for example entity.position += entity.up * bulletSpeed * deltaTime.
The shortest way I could find to do that is this:

entity.position += Vector2.Transform(Vector2.UnitY*speed, Matrix.CreateRotationZ(entity.rotation));

Also, I think incrementing a position by a direction is a very common thing.

EDIT: I’m aware of the local variants, but they still work in the space of the parent object, I want to manipulate my entity in its own local space. I just need a way to convert a direction from local to world.

If you want to convert from local to world or vice verse use the matrix properties on the Transform object.

1 Like

If anybody else stumbles upon the same situation, here’s a couple helpers and extensions I’m using:

public static float DirectionToAngle(Vector2 direction)
{
    return (float) Math.Atan2(direction.X, direction.Y);
}

public static Vector2 AngleToDirection(float radians)
{
    return new Vector2(
        Mathf.sin(radians),
        Mathf.cos(radians)
        );
}

public static Vector2 GetDirection(this Entity e)
{
    return AngleToDirection(e.rotation);
}

public static void SetDirection(this Entity e, Vector2 direction)
{
    e.rotation = DirectionToAngle(direction);
}

Just add them to your static class of ‘utils’, so you can move say a bullet forwards with:

entity.position += entity.GetDirection()*bulletSpeed;

In terms of performance I’m not sure if these trigs are faster than the matrix multiplication, possibly not, but if you use Vector2.Transform(myVector2, MyMatrix2D), there’s a cast to the XNA Matrix, so there are more operations involved there.

Trig will probably be a bit faster than matrix ops. If you ever do need to do Matrix2D stuff it has its own transform methods (note the lowercase “T”).

Hi there :slight_smile: . does Nez.Farseer support FNA?
Also, I’ve tried it with MonoGame, both on 3.5.0 and 3.5.1, along with the 3.6 branch by Robert Wallis, and although they all work fine on Nvidia hardware, I tried them on 2 different Intel cards (G41 and HD3k), and I get a black window with any combination of these 3 versions and these cards.

OLD TEXT Strangely enough, Nez.FNA works perfectly fine, but I can't get Farseer to work :P ... in any case, it's something to do with the way Nez renders the scene, because this works: ``` public class Game1 : Game { public Game1() { new GraphicsDeviceManager(this); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Red); } } ```
OLD TEXT but this doesn't: ``` public class Game1 : Core { protected override void Initialize() { base.Initialize(); scene = Scene.createWithDefaultRenderer(Color.Red); } } ```
OLD TEXT I'm not posting any debug info because initially I'd only like to know if Nez is supposed to work on that hardware at all, since I see that it has some rather fancy stuff like all sorts of image effects, maybe that hardware just isn't "supported" to begin with... it's strange that FNA works though. The error I have when trying to create a FSWorld is on Scene.cs:L409 - `Void Nez.Analysis.TimeRuler.beginMark Method Not Found` (may be inaccurate, this is localized in the system I'm currently on, if necessary I can post better non-localized debug info... I hate when stuff like this gets translated :rage:).