zenspider / graphics

A simple ruby framework to implement games and/or simulations and is designed to follow mathematical conventions, NOT game programming conventions.
http://zenspider.com/projects/graphics.html
53 stars 16 forks source link

How best to compose sprites? #25

Open JoshCheek opened 7 years ago

JoshCheek commented 7 years ago

Playing around with sprites to see how they compose. blit attaches them at the center point of the sprite. It took quite a bit of effort to figure that out and then figure out how to put the sprite in the right spot, given that information. I didn't understand how to do it until I drew a lot more lines on the screen so I could see why things were moving the way they were:

https://gist.github.com/JoshCheek/505d6722e80786461d04cbe8ede3c290#file-1_attach_at_bottom_mid-rb-L225-L230 composing_sprites_1


Since the trees were going in a single direction, I felt like their branches should be billowing in the wind, so I reworked the them to do that. This caused them to be entirely contained in the bottom right quadrant of their sprite. With some versions, they would occasionally go beneath the ground, out of the sprite's viewport. I'm not sure how to get things out of the viewport to be visible other than to make the sprite larger and move the starting point inward. But if I move the starting point, eg if I remove the 3 irrelevant quadrants and have the tree's trunk grow from the bottom left, then I also have to edit the code that determines where the sprite attaches, which is rather unappealing. https://gist.github.com/JoshCheek/505d6722e80786461d04cbe8ede3c290#file-2_attach_at_bottom_left-rb

composing_sprites_2


Not sure if I don't understand how to compose sprites, or if this is just not how sprites were meant to be used (eg this is probably where the Graphics::Body is most useful). Just figured I'd ask if others have a good approach to composition and how they deal with the need to attach at different points without a lot of code churn.

zenspider commented 6 years ago

Can you look at this now? It looks nicer to me, but I don't know what you're going for exactly.

Also, blit centers, but put uses lower left, if that helps.