Bevy 更改角色精靈圖尺寸時,角色為何會浮離地面?
Why does my Bevy character rise above the floor when I change its sprite size?
Bevy 0.17.2 的 Anchor 控制精靈圖相對 Transform 的偏移;改變顯示高度時,置中錨點會令圖像下緣移動,令角色看似浮離地面。應確認來源畫格底部是否代表接地位置,並檢查透明邊距和不同姿勢的接觸位置;裝備則應使用獨立的偏移,不要藉此改動角色的接地錨點。
Disclosure: This draft was generated with AI and checked against the cited primary sources, with a separate AI editorial review. It was prepared for the FrameSprite team, which has a commercial interest in FrameSprite. Proposed examples are not executed tests unless explicitly identified as recorded fixture results.
In Bevy 0.17.2, Anchor is a component controlling a sprite's normalized offset from its Transform. A centered sprite changes its lower edge when its displayed height changes. Set the intended ground anchor or compensate deliberately, rather than moving the camera to hide the mismatch. The pinned Sprite source defines the anchor constants.
Key Takeaways
- Treat the Transform position as a chosen attachment point.
- A bottom-center anchor is useful only when the source frame's bottom is the intended ground.
- Transparent margins and cropped frames can still move visible feet.
Distinguish the canvas edge from the feet
Take an illustrative 64 by 96 frame. If the last eight rows are transparent, anchoring the canvas bottom places the visible feet above the Transform. A bottom anchor cannot infer where shoes, shadow or a weapon belong.
First display the frame on a checkerboard and mark the ground-contact pixel. Check whether every pose uses the same canvas and contact location. The sprite preparation guide explains the earlier normalization step. If a packer trims individual frames, retain the information needed to reconstruct their intended placement.
Use the component API for the pinned version
An existing Sprite entity can receive an anchor with Commands:
// Bevy 0.17.2 fragment; not compiled or executed here.
commands.entity(character).insert(Anchor::BOTTOM_CENTER);
This differs from older snippets that assign an anchor field on Sprite. Follow the API of your dependency. The official scaling example also shows an Anchor component used with a child label.
Draw a small cross at the character Transform and temporarily freeze animation. Change only the displayed sprite height. If the canvas bottom remains on the cross while the feet move, investigate transparent padding or pose framing. If the canvas itself moves, inspect Anchor and any system writing Transform.
Keep equipment attachment points independent
An anchor is a rendering offset, not a replacement for a complete character rig. A weapon entity parented to the character uses the hierarchy's transforms; it does not automatically move to a hand pixel inside the sprite. The hierarchy example demonstrates parent and child relationships.
Choose an explicit equipment offset or frame-specific attachment data. Do not edit the main character's ground anchor to align one sword pose. That couples floor contact to equipment placement and makes the next action harder to fix.
| Symptom | Likely boundary to inspect |
|---|---|
| Canvas bottom moves after size change | Anchor or Transform ownership |
| Canvas stays fixed, feet float | Empty bottom margin or inconsistent poses |
| Feet stay fixed, weapon drifts | Child transform or attachment metadata |
Use the asymmetric mirroring guide when facing direction changes also affect hand placement. The correct anchor does not resolve equipment designed for only one orientation.
Acceptance across poses and scale
Place idle, crouch and attack frames on the same ground line. Compare them at the intended gameplay scale and at a second scale. Check the visible contact point, not only the image bounds.
Keep the gameplay collider visible during this inspection. A rendering anchor change should not silently redefine collision behavior. Document the chosen canvas, anchor and attachment offsets in the animation handoff checklist.
The dimensions in this article are constructed examples. No Bevy project was run, and no claim is made that a single bottom anchor fixes every trimmed or generated sequence.
Avoid changing the gameplay reference point
Keep the actor's logical position stable when the art system changes its anchor. Navigation, collision and saved positions may all depend on that position. If a visual correction currently writes the actor's Transform, consider a visual child carrying the sprite and its own attachment offset. That separates presentation adjustment from movement ownership. Document which entity represents the ground contact and which entity represents the drawable canvas. The hierarchy should make this distinction inspectable without requiring someone to infer it from a screenshot.
Sources and editorial ownership
Primary references checked on October 20, 2026:
- Anchor component and constants
- Official Anchor component usage
- Official parent-child transform example
Editorial owner: FrameSprite Workflow Team. Editorial and verification policy. Report a documentation correction.
來源:DEV Community · dev.to