Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactored to use batch rendering #14

Merged
merged 3 commits into from
Feb 6, 2019

Conversation

zcking
Copy link
Contributor

@zcking zcking commented Feb 5, 2019

Hi @faiface I caught your last comment on my last PR about using batch rendering in this example instead of drawing to the window directly! I just finished reading the wiki today so I went ahead and made the batch tweak. Thanks for allowing me to contribute here--I've learned a lot already about Pixel and have to say I'm having a lot of fun with it!

So quick note btw, I used a map[string]*pixel.Batch where the string key is actually the tileset's image source path. I did this because even though there is only one image used in this example tilemap, the TMX file supports multiple images and could therefore require multiple *pixel.Batch instances; using a map prevents duplicate batches (and sprites) from being created when they use the same image. I learned that technique when working with SDL2 a long time ago :)

@faiface
Copy link
Owner

faiface commented Feb 5, 2019

Great, thanks!

There's just one more problem with your code, sorry :). You draw the batches by iterating over a map. Iteration over a map has a random order (and each iteration order may be different from another). That means, that when you have overlapping sprites from different spritesheets, it's random which one will be on top.

There are multiple solutions to this problem. For example, you can create an additional slice of batches that determines the order. Or you can have an array/slice instead of a map and have a separate map that maps names of spritesheets to indices. Choose whatever solution you like.

Looking forward to merging this :)

@zcking
Copy link
Contributor Author

zcking commented Feb 6, 2019

Thanks for the excellent observation, and suggested solutions! I liked the idea of mapping the image sources to an index "pointer" in a slice/array, so I went with that approach!

@faiface
Copy link
Owner

faiface commented Feb 6, 2019

This looks good now :) Thanks. Merging.

@faiface faiface merged commit 5880f03 into faiface:master Feb 6, 2019
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.

None yet

2 participants