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: https://github.com/prime31/Nez.FNA/pull/1

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: https://gist.github.com/Alan-FGR/838bae004e59a0ecc5925fab4b3cd229 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: https://gist.github.com/Alan-FGR/211ec75246fb7f506d85128017d097d4

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.

https://pastebin.com/raw/B2jmzLTM

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 https://www.youtube.com/watch?v=EBY5KlbPwSk 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?

Thanks!

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.