Nez: free, open source 2D framework

What’s a recommended way to create a level? Can I add child-elements to an entity?

A Nez Scene would be analogous to a level. You can nest Entities via their Transform as deep as you want.

1 Like

Thanks! Another question: how does the camera work? And the zoom? I can’t find relevant hints in this thread, the samples, the wiki and the source.

Edit: Nevermind, I crawled through a couple of github repositories and found it

I’m experiencing a strange behavior when adding child elements to an entity. It seems like the children don’t move to their position unless their parent has a position that is not 0,0. It might be noted that their parent is itself a child to the main entity of the scene. Is this a known issue or expected behavior? Should I try to create an example to debug this? Thanks! Edit: “Solved” it (Don’t understand why the issue was closed though)

Hey guys / gals, I’m having a weird micro lagging issue with follow camera in Nez that I can’t figure out for the life of me. It seems that there is micro lag of camera following a player each frame. Have any of you had a similar issue ?
Here’s a video:
Laggy camera
And source code:
Bitbucket
Any help or suggestions will be greatly appreciated!

Yeah I’ve got that or a similar kind of stutter in my project too? Enabling debug rendering shows why, I think.

@prime31 Furthermore, I’ve wrote a little xml level loader (with a filesystemwatcher that automatically removes the level and it’s chrildren from the scene when the file gets changed) because placing objects by hand kept annoying me and restarting all the time was time consuming. Now I’ve got problems controlling the render order back to front / z-coordinate / render layer. How can I control this? Thanks. Edit: Understood it

Which repositories did you go through @0x25b3? I am trying to figure out the DesignResolution and the Screen size and the CameraBounds and a FollowCamera and I can’t seem to get things working just right. Without the Camera stuff I can get my 40x10 tiled map showing how I want but as soon as I add the CameraBounds and FollowCamera the map isn’t corner to corner and there are dead areas scroll as I move around.

Sorry, didn’t see anything regarding those things. I just searched github for ie. nez and camera to figure out how the followcamera is set up

After finally circling back to this issue and spending another hour with FollowCamera, deadzone, lerp, trying to round the player position, etc. and noticing that the Ninja example also stutters, I’ve started to write my own FollowCamera,… which has the same stutter. I think it’s due to the time when the camera get’s updated, seems to lag behind a little. So my player now directly updates the camera and the problem is gone.

1 Like

Same thing, I’ve using FollowCamera with the same problem and tried tweaking deadzone, lerp, trying to round the player position, etc. And I’ve also tried updating the camera directly but I still see the stuttering problem.

public void update()
        {
            var moveDir = Vector2.Zero;

            if (Input.isKeyDown(_inputs.Up))
                moveDir.Y = -1f;
            else if (Input.isKeyDown(_inputs.Down))
                moveDir.Y = 1f;

            if (Input.isKeyDown(_inputs.Left))
                moveDir.X = -1f;
            else if (Input.isKeyDown(_inputs.Right))
                moveDir.X = 1f;

            var deltaMovement = moveDir * speed * Time.deltaTime;
            var nextPosition = entity.position + deltaMovement;

            entity.transform.setPosition(nextPosition);
            _camera.transform.setPosition(nextPosition);
        }

Could you share your repo that solves this issue? Thanks.

Manage to smooth the jitter making sure that the updated position is rounded.

var deltaMovement = moveDir * speed * Time.deltaTime;
var nextPosition = entity.position + deltaMovement; // updating with this position now, will cause jitter

nextPosition = nextPosition + _overflowVector; // sum previous remainder
_overflowVector = new Vector2(nextPosition.X % 1.0f, nextPosition.Y % 1.0f); // get new remainder
nextPosition = new Vector2(nextPosition.X - _overflowVector.X, nextPosition.Y - _overflowVector.Y); // round

entity.transform.setPosition(nextPosition);
entity.scene.camera.setPosition(nextPosition);

I ran into this issue as well.

I believe this is happening because scene objects (which is where the camera lives) are updated before entities. It was causing horrible stutter for me when my design resolution was set to something low (480x360)

I scaled everything up 3x and am now running at a higher design resolution of 1920x1080 and the stuttering is gone.

I’m not sure how to fix the stutter in row resolution without serious modification to the way Nez does rendering internally. I’m not sure if the above solution of rounding the position up will work well on a tiled map following a character who is moving via the tiledmap function… but if someone gets that (or anything) fully working I’d love to read about it.

Prime31 made additions to movement code to account for a subpixel movement, I have tried it in my own project and it works like a charm. Checkout the latest nez version and give it a try.

I am using Nez and having some issues with the boxcastBroadphase method in Physics. I have create an entity that attaches a collider to itself, like this
public Solid(int x, int y, int width, int height) { this.Collider = new BoxCollider(width, height); Flags.setFlagExclusive(ref this.Collider.physicsLayer, 10); this.transform.setPosition(x + (width / 2f), y + (height / 2f)); this.addComponent(this.Collider); }

but when I use this to get the colliders with the same mask, it does not return any of the colliders

this.BroadphaseSolids = new HashSet<Collider>(Physics.boxcastBroadphase(this.camera.bounds, 10));

From what I understand from the documentation, this should give me all of the colliders with the layer mask 10 that are inside or intersecting the camera bounds. If I remove the 10, and just ask for all of them, I get 26. When I add the layer mask, I get none. Is there something I am missing?

I believe the Broadphase message takes a mask, not an individual layer.

Thanks for the quick reply. It looks like that was the problem. I haven’t had much experience with layer masks.

yeah, the physics system in Nez isn’t super intuitive. It took me a bit of time to wrap my head around it but now that I understand it, I really like it.

Hey, I am using Nez to make my own Tile Engine and am struggling to get the layerDepth to work when rendering my tiles.

I have one component called TileMapComponent, which implements IRenderable and takes care of rendering all of the tiles on the map through a for loop which calls Batcher.draw(). For some reason, specifying a layerDepth in the draw() method doesn’t do anything, it seems that it only worries about draw call order.

I have found a “hack” to get it working by manually sorting all of the tiles that are at the same position but on different layers and then calling them in order. But then it still doesn’t work with any external entities (say I have a player entity that is on the 1.0f depthLayer, it renders behind the 0.5f tiles simply because it is declared/called before them). I’ve even tried inverting the depthLayer, setting the DepthStencilState, etc. Nothing worked.

So does Nez’s Batcher not support depthLayer? or am I misunderstanding something?

Here’s a small code sample which shows my draw calls.

Note: Since all of the tiles are rendered by one component, the renderableComponentList only includes ONE component when I try to debug.

Thanks!

If you trace through the Batcher code you will see that layerDepth works exactly like SpriteBatch. There is no difference at all.