Skip to content

Add object layer support#15

Merged
wildfiler merged 3 commits into
wildfiler:masterfrom
vinnydiehl:objects
Apr 29, 2023
Merged

Add object layer support#15
wildfiler merged 3 commits into
wildfiler:masterfrom
vinnydiehl:objects

Conversation

@vinnydiehl
Copy link
Copy Markdown
Contributor

This commit adds an API for Tiled's object layers. It adds 2 classes:

  • TiledObject - Represents a single object
  • ObjectLayer - A layer of one or more TiledObjects

refs #14

Comment thread lib/tiled/attributes.rb Outdated
@vinnydiehl
Copy link
Copy Markdown
Contributor Author

While I'm not 100% happy with rendering the debug from the library like this, it's certainly the most performant idea... besides the cost of having to calculate the lines every tick, you'd also have to build and flatten an array, so it'd be heavier on memory too, methinks...

@vinnydiehl
Copy link
Copy Markdown
Contributor Author

vinnydiehl commented Apr 29, 2023

To expand on what you said in #14 about breaking off the rendering code to its own library and making this a simple, lightweight API for the parsed XML files, I like that idea.

I'm picturing a Tiled::Renderer class with a camera, parallax, etc... and some interface to change maps. In there my #render_debug function will make more sense and will integrate seamlessly with the camera, and we'll do something similar with Tile layers.

When I get around to collisions I'll think about a modular implementation for that as well.

What do you say we merge this and discuss what to extract into a separate rendering library in a different issue? Let me know if you'd like anything else on this pull- I want to use Tiled in an eventual production DR game, so you can expect my continued help with some of the other things we've discussed.

EDIT: Whoops, found an off-by-one error, fixed here in the last force push.

@vinnydiehl
Copy link
Copy Markdown
Contributor Author

vinnydiehl commented Apr 29, 2023

So I decided to test the limits of how many polygons you can draw in this manner and as it turns out, my fears about rendering too many line primitives proved to be well-founded 😞 As few as 6 polygons on-screen tanked my FPS to ~15.

I'm not sure if there's a way around this while keeping the library compatible with the standard license. This would be easy with triangle primitives, but alas, it's a sacrifice we'll have to make. This code is soon-to-be extracted, so it won't be this library's problem anyway. ¯\_(ツ)_/¯ The fill has been removed for polygons.

This was causing a massive performance hit, unfortunately.

Rebased onto the color corrections that you made earlier.
@wildfiler
Copy link
Copy Markdown
Owner

Oh, while I was in the process of merging I missed your new commits. I made some tweaks in master, mostly adding usage of Tiled::Color class. Now I'm looking into the performance of polygons, maybe render targets will help, if not, will remove filling.

Comment thread lib/tiled/object_layer.rb
@vinnydiehl
Copy link
Copy Markdown
Contributor Author

Ahhhh, I had found a bug and saw conflicts so I just rebased it on top of the color fixes that you had made, haha. I totally missed that you had color conversions built-in already.

Comment thread lib/tiled/object_layer.rb Outdated
@vinnydiehl
Copy link
Copy Markdown
Contributor Author

Yeah, I remembered what you had said about being able to tint sprites, which led me to realize that I was caching the first color that was used 😓

The first color that was loaded was being cached. Fixed by caching a
white circle sprite and coloring it to order.
@wildfiler wildfiler merged commit 348fcef into wildfiler:master Apr 29, 2023
@wildfiler
Copy link
Copy Markdown
Owner

Thanks a lot, this is awesome changes :)

@wildfiler
Copy link
Copy Markdown
Owner

To expand on what you said in #14 about breaking off the rendering code to its own library and making this a simple, lightweight API for the parsed XML files, I like that idea.

I'm picturing a Tiled::Renderer class with a camera, parallax, etc... and some interface to change maps. In there my #render_debug function will make more sense and will integrate seamlessly with the camera, and we'll do something similar with Tile layers.

Yep, I was thinking about the same.

When I get around to collisions I'll think about a modular implementation for that as well.

Tiled::BigDragonCollider :D

What do you say we merge this and discuss what to extract into a separate rendering library in a different issue?

I would rather focus on adding other Tiled TMX features first, and then focus on rendering. But it is just my plans :)

I want to use Tiled in an eventual production DR game, so you can expect my continued help with some of the other things we've discussed.

Thanks a lot! I would love to see your game :)

@vinnydiehl vinnydiehl deleted the objects branch May 3, 2023 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants