Closed fosskers closed 2 months ago
Flipping the sprite like this will make the geometry's backside show the camera. By default backface culling is on, and you probably haven't turned it off.
(defmethod setup-rendering :after ((main main))
(disable-feature :cull-face))
Worked like a charm, thanks again. Key points for anyone from the future:
My entity definition is:
(define-shader-entity farmer (animated-sprite scaled-entity located-entity)
((sprite-data :initform (asset 'farm 'farmer))))
Notice that scaled-entity
comes before located-entity
in the inheritance order. Otherwise he will flip, yes, but also be teleported around.
My tick
handler looks like:
(define-handler (farmer tick :before) ()
(let ((movement (directional 'move)))
(incf (vx (location farmer)) (vx movement))
(incf (vy (location farmer)) (vy movement))
(cond ((> (vx movement) 0) (setf (scaling farmer) (vec 1 1 1)))
((< (vx movement) 0) (setf (scaling farmer) (vec -1 1 1))))))
Although, this might be allocating a new vector for every tick (of movement). Doing it the Kandria way, shown above, would be more efficient since you're passing an integer directly to scale-by
. You could also argue it's clearer for the entity to only manage its "direction". Is it obvious what effect setting scaling
directly here in the handler has? Probably not.
Here is how Kandria sets up its own setup-rendering
, where we indeed see culling disabled.
Instead of allocating a new vector every time you can just use (setf (vx (scaling farmer)) -1)
Right, duh, just as I'm doing for the location
. Thanks.
Hi, I'm having some trouble getting sprites to flip / pivot. I've tried three approaches:
Emulating Kandria
Emulating
facing-entity
and manually updatingdirection
as is done for theplayer
andcritter
classes in various places.Effect: up/right/down movement works as expected, but when I press left, the farmer sprite becomes invisible. Pressing right again makes him reappear.
Two possibilities come to mind:
direction
directly onfarmer
and not in a similar abstractedfacing-entity
class, the order in whichapply-transforms
runs w.r.t.located-entity
might be in conflict.scale-by
is called in this way. The assumption is based on Kandria, but maybe I missed some detail while reading its code.Farmer as a
scaled-entity
Instead of flirting with the powers of
apply-transforms
directly, we letscaled-entity
do the work. Intick
we have:Unfortunately the farmer still turns invisible when the X-scaling is negative. The inheritance order of
located-entity
andscaled-entity
doesn't affect this particular outcome.Farmer as a
pivoted-entity
Intuitively the word "pivot" seems like what I'd what. Referencing the Scene Graph page of the guide:
The
pivot
slot holds(vec 0 0 0)
as its default, and seeing that this class isn't used in Kandria, I wasn't sure what constitutes a proper "pivot vector", so the following is almost certainly wrong (seeing thatapply-transforms
onpivoted-entity
calls down totranslate
, and then lower into your math library):Although even with this, left-presses don't make the farmer invisible, but they also don't flip the sprite.
If I should indeed just do it the Kandria way with manually tracked
direction
, can you think of a reason whyscaled-by
would turn him invisible? Thanks again.