Nez: free, open source 2D framework

OLD TEXTOK, there's something really strange with Nez.FarseerPhysics under FNA... when you try to create a FSCollisionBox component, you get this error: ```plain System.MissingMethodException: 'Method not found: 'Microsoft.Xna.Framework.Vector2 Nez.Transform.get_scale()'.' ```
OLD TEXT stack trace: ``` > Nez.Farseer.FSCollisionPolygon.onAddedToEntity() Line 72 Nez.ComponentList.updateLists() Line 188 Nez.ComponentList.update() Line 302 Nez.Entity.update() Line 398 Nez.EntityList.update() Line 169 Nez.Scene.update() Line 417 Nez.Core.Update(Microsoft.Xna.Framework.GameTime gameTime = {Microsoft.Xna.Framework.GameTime}) Line 224 Microsoft.Xna.Framework.Game.Tick() Line 526 Microsoft.Xna.Framework.SDL2_FNAPlatform.RunLoop(Microsoft.Xna.Framework.Game game = {TestGame}) Line 778 Microsoft.Xna.Framework.Game.Run() Line 421 Program.Main(string[] args = {string[0]}) Line 73 ```
OLD TEXT However, I've no idea what's that 'get_scale' thing, my best guess is that it's some auto method for the getter of the 'scale' property, maybe for the portable stuff.

Also, it was necessary to manually update Nez.FNA to include some files in Nez (say, EntityExt.cs) in order to have Nez.Samples to work properly, is there a tool to automate that? (automatically updates Nez.FNA.csproj with the files in Nez.csproj)

Overall Nez seems to work much better under FNA; except the deferred renderer which doesn’t work at all, but the other samples run much faster and run perfectly on every hardware I tested as opposed to the MG version which seems to require GL3.3+ to run correctly, but then again, I’ve lots of problems with MG in terms of hardware support, if you do anything a little bit more complex it breaks completely, while FNA seems extremely reliable, the strange part is that I though after the version 3.6 MG would be quite similar to FNA under the hood.

Yep, it turns out the problem was the pesky portable stuff :smile:. I made a non-portable version linking the portable sources, it’s working perfectly for me, but I don’t know if it’s an appropriate solution, I’m not experienced in these portable things, but the FNA version isn’t portable anyway is it? So we might as well just use a non-portable Nez.Farseer… in any case, I’ve made a PR with some other goodies, feel free to reject it of course if you feel it’s not appropriate:

Hi there.

Everything is working fine with FNA, Nez is really amazing :slight_smile: … I have one more question though :laughing:, I’m using a screen space renderer for my UI, but I’d like to use pixel-perfect scaling on it independently from the game, but setDesignerResolution is a Scene method, and I couldn’t find a way to set the render target size for the renderer, nor a way to run another scene without another Core just for the UI. How can I achieve that?

Bump :blush:… any minimal example on how to have an independent UI scene would do… I’ve tried modifying the samples code since it uses an independent renderer for the UI but that wasn’t fruitful.

You can take the contents of any render layer and stick it in a RenderTarget by just setting the RenderTarget property. You can then do whatever you want with the output.

OK, will try. Thanks. I wasn’t able to achieve pixel-perfect scaling independently, and also I couldn’t find a way to change the size of the render texture on-the-fly, but lemme try a bit more, I’m not very used to the API yet, could be missing something :stuck_out_tongue:

I really couldn’t find a way to achieve that, the problem is that I need proper culling and also the UI to behave correctly according to the screen, so I’m going to just use another Scene for that, it’s not the end of the world and I could even run it in another thread, if anybody is interested in the code I’ve abandoned, here you go: it works quite OK, but there are problems with culling and debug drawing, culling I guess could be resolved with a separate camera, but debug drawing would need changes in Debug.render so it renders to a render target of our choice.

Here’s how I solved it in the end:

Multiple scenes work perfectly, had to remove transition support though :stuck_out_tongue:

Have problems building pipeline tools. It can’t find Microsoft.Xna.Framework.Content.Pipeline namespace. Wasn’t able to find Ioniz.Zlib as well, but I’ve solved it myself by downloading appropriate assembly.

I am having some issues with slopes using the TiledMapMover. Often, when my entity is moving from a normal tile up a slope tile, sometimes the entity can’t move forward. Basically, the entity will keep trying to move right but won’t move any distance, as if it is running into a wall. Sometimes it will eventually start moving up the slope, but I am unsure what the TiledMapMover sees as different, where sometimes the entity is blocked, others it’s not.

Also, are there any constraints to make slopes work correctly? For example, does the width and/or height of the bounding box need to be less than the width/height of a tile? Is there a max velocity to be able to move successfully up a slope? I noticed that there is a colliderHorizontalInset, and colliderVerticalInset, do these need to be changed depending on the relative size or speed of an entity relative to the tile width/height?

Thanks in advanced!

The only constraint is that your Entity’s Collider width must be less than the width of a tile. If you have a fast moving Entity you should break up the movement into pieces that are less than a tile width/height and just to multiple checks in a row with them.

The constraints fixed a lot of the issues! However,there is still one thing that is not working. For slopes at least 2 tiles high, there are some cases where the edge of the entity collides with the tile horizontally adjacent to the slope tile before the entity has ascended to the tile above it. This causes the entity to get stuck as a wall tile is preventing horizontal movement. I think the issue is related to line 259 on TileMapMover.cs

            if (direction.isHorizontal() && collisionState._lastGroundTile != null && collisionState._lastGroundTile.isSlope() && _collidingTiles[i].isSlope())

The last && piece only ignores a collision tile in horizontal movement if it is also a slope tile. I removed the last &&, changing the line to

             if (direction.isHorizontal() && collisionState._lastGroundTile != null && collisionState._lastGroundTile.isSlope())

And it fixed the issue. The only problem is that this creates a side effect, where if your slope leads directly to a wall, the entity will go be able to go through the wall (as the above code exempts all horizontal collisions while on a slope), which messes everything up. This case is easy to avoid, but I think the best solution may be to determine if the tile is adjacent to a slope tile and exempt those tiles from horizontal movement, but I haven’t come up with the best way to do that yet. I can probably provide pictures/examples if it would be useful to illustrate the issue.

Does the source for exist somewhere? One would think it’d be a sample but I can’t seem to find it anywhere.

That demo was most definitely not production worthy code. It was just a big mess of a Table with a bunch of controls tossed in.

A bad example would still be better than no example. :smiley:

1 Like

Hey, apologies if this has already been mentioned (I did a search, but couldn’t find an answer). From my understanding based on the videos and skimming through the source for the Tiled map related source files, there’s no support for tileset collisions, correct?

I ask because currently I’m building my Tiled maps with a 16x16 size, but some of the tiles are 32x32 (to get around the constraints of Tiled map sizes when using multiple sized tiles). Therefore when generating a collision layer through Nez, it only generates a collision box of 16x16 in the base point of the tile sprite (which I can see making sense). But to then get around this limitation, I would use the Tileset specific collision editor, however it doesn’t appear to be supported.

From what I can tell, my options in this case would be to A) Manually draw on collisions to the tilemap with objects (not ideal), or to use 2 different TIled maps, one for each grid size, and overlay them (even less ideal).

I’m just wondering if there’s any support for something like this that I’ve missed with Nez, or if you have any plans to support the tileset collision editor in the future?


Generating collision data for multiple tile sizes isn’t supported out of the box but you could certainly do something like that. I would just have a look at the current collision generation code then right after loading the Tiled map just add your double sized Colliders with a similar snippet of code.

Alternatively, a wholly different approach could be to go with something akin to the TiledMapMover which doesn’t use Colliders at all. It just uses the raw tile map data instead.

Perfect, thank you for the swift response! I’ll do some digging into your suggestions and see what I can do.

Hi! I’m just getting started with Monogame + Nez, so apologies if I missed something obvious.

I’m trying out the deferred lighting with pixel art, but it seems to be blurring the screen. Is there a way to disable blur with deferred lighting?

Im not sure about the specifics of your situation.

You can try to set the sampler state to point or point and clamp (clamps really about edges)), either in your shader or directly from your Draw method.

GraphicsDevice.SamplerStates[0] = new SamplerState() { Filter = TextureFilter.Point /* , AddressU = TextureAddressMode.Clamp , AddressV = TextureAddressMode.Clamp*/ };

Note. typically you define the states at the start of your game1 then just set it when you need to.

Dunno if that will work for deffered rendering i never tryed to do it yet.