Nez: free, open source 2D framework

That old test project was not of good enough quality to be released. It was very sloppy code thrown together for testing various UI bits.

There is no animation system built into the UI but Nez has a tweening system built in that can tween any basic math type so you can use it to tween just about anything.

Thanks. One more question, is it advisable to have two tables under one stage in a UICanvas? Iā€™m having trouble centering interactable elements(buttons, menus) when they are in the same table as my information ui elements(life bars, score, etc.).

You can certainly nest multiple UITables. In fact, some of the controls are just UITables under the hood.

Hello all, I have a function that moves my character a specified number of pixels that looks like this:

            if ( Input.isKeyPressed( Keys.W ) )
                battleMovement.mover.move( new Vector2( 0, -120 ), out battleMovement.res );
            else if ( Input.isKeyPressed( Keys.S ) )
                battleMovement.mover.move( new Vector2( 0, 120 ), out battleMovement.res );
            else if ( Input.isKeyPressed( Keys.A ) )
                battleMovement.mover.move( new Vector2( -128, 0 ), out battleMovement.res );
            else if ( Input.isKeyPressed( Keys.D ) )
                battleMovement.mover.move( new Vector2( 128, 0 ), out battleMovement.res );

This works obviously but what Iā€™m hoping to do is to move the entity the specified distance and see the movement happen other than just the entity ā€œpoppingā€ into position. Is there a good way to do this using Nez or is there someone who could clue me in on the best way that I could achieve this? Thanks!

If you want to see the motion you need to break it up into smaller steps and do the movement a little bit each frame. You can do it manually or via a fire and forget tween (see the tween* extension methods on Transform).

Are you suggesting that instead of a mover I use transform with one of the tweening methods?

It depends on if you want collision detection or not. If you do, break up your movement into smaller chunks and use the Mover.

Thank you for the informative response! : )

I would like to use a Xbox One Controller to handle input. What is the proper way to do this in nez? This pilfered code from the YouTube Tiled demonstration moves the ProtoTypeSprite happily.

if (Input.isKeyDown(Keys.Left)) _velocity.X = -moveSpeed;

So I authored this beauty after reading GamePadData.cs

if (GamePadData.isButtonPressed(Buttons.DPadLeft)) _velocity.X = -moveSpeed;

I am not an experienced programmer by any means but the logic seemed comparable. The impudent IDE demanded an object reference for non-static field, method or property.

After much research and failed solutions I returned, bestowing this:

GamePadData myGamePadData; 

and this:

if (myGamePadData.isButtonPressed(Buttons.DPadLeft)) _velocity.X = -moveSpeed;

That got rid of the squigglies but produced an unhandled exception, ā€œobject reference not set to an instance of an objectā€ I know that these are simple coding errors due to my lack of understanding of C# and OOP. I feel like itā€™s the simplest, most basic oversight but I donā€™t see it. I know Iā€™m misusing the GamePadData class and would like to see a proper implementation to learn from my mistakes if I may. I donā€™t ask for help carelessly, and appreciate any thatā€™s offered.

Thereā€™s an example right in the Platformer Sample. Itā€™s just what I was after. Great framework, very neat and concise. Almost entirely dummy proof too. :blush:

1 Like

Hi. I am trying to run Nez with DirectX. It seems to work but I got a problem on my Effect. For instance, I try to use the SepiaEffect on a single image sprite. I builded the SepiaEffect.fx with 2MGFX with the DirectX_11 Profile.

Following what I see in the samples doesnā€™t seem to make it. My guess was :

            var hero = myScene.createEntity("hero");
            hero.transform.position = new Vector2(200, 200);
            hero.addComponent(new Sprite(myScene.content.Load<Texture2D>("Characters/001-Fighter01")));
            hero.getComponent<Sprite>().material = Material.defaultMaterial;
            hero.getComponent<Sprite>().material.effect = content.loadNezEffect<SepiaEffect>();

But my sprite is not rendered at all. If I add a background sprite under my sprite hero, I get a sepia color all over the screen.

Do you happen to have a simple effect example on a single renderable ?

Nez only supports OpenGL. Nothing at all was ever tested for DirectX so you are on your own if you want to go that route.

Hi there. Iā€™m struggling a bit with the UI, first problem is that text rendering isnā€™t perfect, this simple code:

var canvas = createEntity("ui").addComponent(new UICanvas());

var skin = Skin.createDefaultSkin();

var table = canvas.stage.addElement(new Window("window", skin)).setMovable(true).setResizable(true);
table.pad(10).setPosition(10, 10);
            
var inpt = new TextField("input", skin);
table.add(inpt).pad(10).setRow();

var button = new TextButton("click", skin);
table.add(button).size(100,20).setRow();
            
table.pack();

produces this:

Everything works, but besides the ugly rendering, a resizable and movable window has an extremely small drag area on the titlebar to move, like 1px or so, a bit up and you resize it.

Also, when you just want to pass a simple image in an Nez.UI.IDrawable typed parameter, is SubtextureDrawable the appropriate object to use?

Is there a multi-line text input, or maybe a multi-line mode for the normal text input?

Thanks in advance.

It seems to be a bug or incompatibility with FNA (17.05). Somewhere a value is off by one, Iā€™ve printed the usual suspects from FNA but the values are consistent, at least with the window and framebuffer dimensions. Anyway, I managed to workaround that with a quick hack:

On ECS/Camera.cs, add the following lines before the inverse transform matrix calculation (around L330):

float offX = Core.graphicsDevice.Viewport.Width / (Core.graphicsDevice.Viewport.Width-1f);
float offY = Core.graphicsDevice.Viewport.Height / (Core.graphicsDevice.Viewport.Height-1f);
_transformMatrix *= Matrix2D.createScale(offX, offY);

On ECS/Scene.cs modify the following lines to read as follows (around L557):

var renderTargetWidth = screenSize.X-1;
var renderTargetHeight = screenSize.Y-1;

Thatā€™s it!

On a related note, Iā€™m really enjoying Nez, really well-made gamedev library! The other questions are still valid though :slight_smile:

EDIT: Also, this question may sound ridiculousā€¦ but how do I enable vsync? =/

I want to make it so that an Entityā€™s Sprite flashes white when it gets hit. I think I need to create a shader and use that, but I am not sure how to apply a shader to a Nez Sprite. Is there any tutorial or reference describing how to do this? Am I supposed to be using a PostProcessor somehow? Thanks in advanced!

Nez includes a SpriteBlinkEffect that you can use to fully color a Sprite. All Effects are applied via a Material and all RenderableComponents can have their Material set via the setMaterial method.

1 Like

Hi!
Is Nez ok with 3.7 build ?

Cant say I have any idea what 3.7 is bringing. All you have to do is change the Reference to your 3.7 build and the compiler will let you know straight away.

Matrix.Rotation and Matrix.Scale got removed, so if Nez uses that, you should switch to Matrix.Decompose.
Other than that there are no breaking changes so far.

That should be all good. Nez uses its own 2D matrix class.