oakes / play-clj

A Clojure game library
The Unlicense
939 stars 73 forks source link

Independent rotation for entities within a bundle? #37

Closed Misophistful closed 10 years ago

Misophistful commented 10 years ago

I have a bundle entity where I'd like both sub-entities to move in unison, but for only one of them to rotate when I change :angle. Is that doable?

To give an example: imagine a game with tanks that can only move backwards and forwards, but with rotating gun turrets. Would that be achievable with a bundle, or would it need to be handled in another way?

oakes commented 10 years ago

You would have to change the :angle of the entity inside the bundle. I imagine it would look something like this:

(assoc-in my-bundle [:entities 0 :angle] 45)
Misophistful commented 10 years ago

I haven't been able to get your assoc-in approach to work. I think it's because :entities contain a list, rather than a vector. Should I be converting it to a vector each time? Or is this something that perhaps play-clj should be handling?

oakes commented 10 years ago

Yeah you're right, I should be coercing it into a vector. I just pushed 0.3.8-SNAPSHOT that should do this. Thanks for pointing this out.

Misophistful commented 10 years ago

You're welcome, and thanks for fixing it!

Misophistful commented 10 years ago

assoc-in works perfectly to add :angle to an inner entity with 0.3.8-SNAPSHOT, but the inner entity still seems to be inheriting its angle from the parent, and ignoring its own :angle.

Here's one of my entities:

#play_clj.entities.BundleEntity
{:entities [#play_clj.entities.BundleEntity
{:entities [#play_clj.entities.TextureEntity
{:object #<TextureRegion com.badlogic.gdx.graphics.g2d.TextureRegion@1d78a69c>, :angle 0}
#play_clj.entities.TextureEntity
{:object #<TextureRegion com.badlogic.gdx.graphics.g2d.TextureRegion@5c025ae1>}]}
#play_clj.entities.TextureEntity
{:object #<TextureRegion com.badlogic.gdx.graphics.g2d.TextureRegion@1e9c98f8>}],
:y 713, :coords [-1 3], :angle 180, :id :2-water, :piece? true, :player 2, :element-type :water, :x 224, :hit-box #<Polygon com.badlogic.gdx.math.Polygon@3afed17b>, :selected? false, :moves-remaining 3}

You can see :angle 0 in the first TextureEntity, but that texture is still being rendered with an angle of 180. (I also tried moving :angle 0 to the inner bundle instead of the texture, but that didn't work either.)

What might I be doing wrong?

oakes commented 10 years ago

At the moment, any key in the bundle will override a key in an a bundle's entity. I could change this behavior, but I'm not sure which matches expectations more.

oakes commented 10 years ago

I just pushed a new 0.3.8-SNAPSHOT that reverses the precedence, so an internal entity's keys will override its bundle's keys. I think you are right that this is more logical, and seems to be more consistent with things like CSS precedence rules.

Misophistful commented 10 years ago

After updating to the latest 0.3.8-SNAPSHOT all of my piece entities (the nested bundle entity I posted earlier) have disappeared from the screen. Could the reversed precedence have caused this? Do I need to have :x and :y in all of the sub-elements now?

oakes commented 10 years ago

Yeah I must've not tested correctly before, because I get the same thing. It turns out that my merging was eliminating the entity type, so it didn't know how to draw them. I just pushed a new snapshot that adjusts this, so please let me know how that goes.

Misophistful commented 10 years ago

The new update fixed it, and the independent rotation is working perfectly. Thank you so much!