Nez: free, open source 2D framework

Now, I have another question about sequential tweens. (Excuse me for this may being a common question, not a specific question of Nez.)

How should I run such this operation?:

There is a white rectangle.
(1)rotate the rectangle, and wait until this(1) tween finishes
(2)color the rectangle with red for some duration, and at the same time,
(2.5)move upward the rectangle and wait until this(2.5) tween finishes
(3)(and more operations…)

Also, this sequential tween(operation) can be waited with an Enumerator.

the (2) seems to be an issue to me. Does Nez support such sequential operations(tweens) in design? or should I somehow make such a sequential tween myself? (maybe using the delay values or a helper class)

Thank you.

I wrote
(2)color the rectangle with red for some duration, …

This means, for example, the value changes like (0, 51, 102, 153, 204, 255) in each frames. It’s a tween.

You have a few different options here. For just a straight chain of tweens you can just call setNextTween on each. When the first tween completes the next tween will begin for as many as you chain.

Another option is to use coroutines which are really handy for any type of sequence. The Tween class has a waitForCompletion that you can yield on in a coroutine to setup your timings. Something like the following pseudo code would do the trick:

Core.startCoroutine( myAnimationThing() );

IEnumerator myAnimationThing()
   // start the first tween to kick things off
    var firstTween = setupTweenAndStartIt();

    // wait until the first tween finishes
    yield return Core.startCoroutine( firstTween.waitForCompletion() );

    // start up the second tween
    var secondTween = setupAnotherTweenAndStartIt();

    // wait until the second tween completes
    yield return Core.startCoroutine( secondTween.waitForCompletion() );

    // you get the point by now
    var thirdTween = setupYetAnotherTweenAndStartIt();
    yield return Core.startCoroutine( thirdTween.waitForCompletion() );

Coroutines can be used for more intricate timing as well:

Core.startCoroutine( myAnimationThing() );

IEnumerator myAnimationThing()
   // start the first tween to kick things off
    var firstTween = setupTweenAndStartIt();

    // wait until the first tween finishes
    yield return Core.startCoroutine( firstTween.waitForCompletion() );

    // start up the second tween
    var secondTween = setupAnotherTweenAndStartIt();

    // wait half a second
    yield return Coroutine.waitForSeconds( 0.5f );

    // start up another tween
    var thirdTween = setupYetAnotherTweenAndStartIt();

    // wait for it complete
    yield return Core.startCoroutine( thirdTween.waitForCompletion() );

And yet another option (if you prefer a class based approach) would be to port over the TweenParty or TweenChain from here. The tween system in Nez is just my old ZestKit Unity library.

Thank you for your detailed answer.

Now, I will use coroutines. I was afraid of making many coroutines out of a function, but it’s powerful. (Well, I hope local functions will be implemented soon.)

  • setNextTween is cool in some patterns, however, in my last example, there is the issue. Both 2 and 2.5 tweens have to be started at the same time.

  • TweenParty doesn’t seem to be so flexible. TweenChain’s feature seems to be included by Nez’s Tween class’s.

Also, I tried imaging a helper class which is so flexible that I need not write coroutines. However, I found it requires much more words.

I have looked for a good game engine for me. Only HaxeFlixel and Nez matches me needs, and I found Nez’s document and the code are cool. I`ve never thought I can glasp a framework before, and thank you again.

Glad to hear you are liking Nez! Coroutines are very efficient and they provide a ton of flexibility. I use them for all sorts of stuff where timing is important.

Using a framework takes a bit of getting used to since it has a lot more flexibility than an engine but once you get used to it the flexibility is so handy.

Is there something special that needs to be done in order to enable the debugging console? Simple pressing tilde isn’t working for me. I’m using Xamarin Studio 6.2 and the latest Nez source.

Thanks for the framework, prime31!

The debug console will only exist in Debug builds. If you do a Release build it wont be there.

Thanks for the reply!
I assumed that was the case. As well as ensuring I was in Debug mode, I also ensured the debug constant was defined. EDIT: I thought maybe the key was broken on my keyboard, so I changed the sources to use the space-bar since I know for a fact that key works. Still no console.

Lovely, this project taught me how deferred lighting works once I figured out how the rendering worked in your framework.

I have little to no experience with shaders and my ambition was to get some basic understanding.

The whole part about self illumination per texture due to how materials are handled was a bit trickier and I still don’t understand how the SetRenderTargets (multiple) works in MonoGame however I managed to come up with a solution which I understand myself :slight_smile:

Basically I ended up using SpriteBatch for all the drawing apart from the light generation.

SetRenderTargets lets you bind multiple render targets simultaneously. You can then have any shader write to all of the render targets in one go without needed to have a separate shader for each time you want to write to a different render target.

Alright, does that mean it’s index based and corresponds to COLOR0, COLOR1 etc within the shader?

GraphicsDevice.SetRenderTargets(_diffuseMap, _something);
would correspond to:
COLOR0 will write to the _diffuseMap render target
COLOR1 will write to the _something render target

Yes, this is how it works.

So after watching the Tiled maps tutorial for nez on youtube ( ) I tried to implement it. Everything worked fine, the map loaded everything’s there. My question is how do you add other collidable objects to the scene?
I have the main player in there (works just fine) and an NPC that simply moves back-and-forth (also works). The problem is that the player and NPC don’t register collisions with each other.
Any help would be much appreciated!

Here’s the code where it loads and sets up players and NPCs.

p.s. I still don’t know why the freakin’ debug console doesn’t work for me!

Collision checks are pretty simple with Nez. There are several different methods available in the Collider class but the simplest is probably to just call Collider.collidesWithAny. You get back the details of the collision including the normal, penetration distance and the Collider that is being overlapped. Just call that each frame and you will always know every other Collider that your Collider is overlapping.

Ah, OK. Thanks! I assumed TiledMapMover.CollisionState and the TiledMapMover would handle everything. But they are strictly for the tiled levels. Sorry that I was being to ignorant to figure that out myself :).

I was trying to follow through the setup instructions located at but was unable to compile the PipelineImporter project because of missing references (Ionic.Zlib and Newtonsoft.Json). Did I miss a step? Are we supposed to retrieve those ourselves and stick them in the project folder?

edit: I dealt with this by opening the Nuget manager and updating them. Not sure why VS didn’t automatically download the packages.

VS sometimes gets stupid and forgets to download NuGet packages. Usually just closing and reopening VS kicks it into gear but sometimes you have to do it manually as you found out.

Hi. This is actually more of a design question for ECS implementend on the sample projects. Is it standard to actually have a “Ninja” component which handles the communication between the components as well as the input? Or are you planning on a different approach with the game project you are currently working on(the one you mentioned you will share to us once completed)?

There are many different ways to work with the ECS. It doesn’t impose any strict rules. You can go with the Entity systems approach where Components just hold raw data, you could have facilitator Components that work with multiple other Components (like in the Ninja Adventure) or you could keep your Components entirely separate and decoupled. It is entirely up to you how you like to do things. You can even mix and match styles if you prefer using the best one for each specific situation.

I just have to say this looks quite nice! I’m definitely going to check it out for my next project! (already too far along with the current one lol)

I’ve built Nez-Samples on macOS 10.12.2. The application starts and shows the “moon” texture and buttons list, but I can’t click on any of the buttons. Any suggestions?

I used the latest Xamarin Studio and Nez-Samples referencing MonoGame 3.5.1