You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ursina Engine自定义动画实现问题求助

Ursina Engine: Custom Frame Animation Not Displaying

I get it, it’s frustrating when built-in animations work flawlessly but your custom frame setup doesn’t show anything at all. Let’s break down why your code isn’t working and fix it step by step.

What’s Wrong With Your Original Code?

The main issue is that you’re passing 'test' as the first argument to the Animation class. When using the frames parameter to define custom textures, Ursina still tries to load a built-in or named animation resource matching 'test'—this conflicts with your custom frames and prevents them from rendering properly.

There are also a few small tweaks to ensure your animation shows up reliably:

  • Double-check your file paths (make sure your animation folder exists in your project root, and filenames are spelled correctly—note that paths are case-sensitive on macOS/Linux!).
  • Adjust the scale value (a scale of 1 might be too small depending on your window size, making the animation hard to spot).
  • Verify your textures are loading successfully by printing them (e.g., print(coin1) should return a Texture object, not None).

Fixed Code Example (Simplified)

Instead of loading each texture individually, you can pass a list of file paths directly to frames—Ursina will handle loading them automatically. This reduces clutter and potential errors:

from ursina import *
app = Ursina()
window.color = color._20

# Leave the first argument empty to avoid conflicting with built-in animations
animation = Animation(
    '',
    fps=6,  # Adjust to make the animation smoother
    scale=2,  # Larger scale ensures the animation is visible
    filtering=None,
    autoplay=True,
    frames=[
        'animation/coin1',
        'animation/coin2',
        'animation/coin3',
        'animation/coin4',
        'animation/coin5',
        'animation/coin6'
    ]
)

EditorCamera()
app.run()

Alternative: Load Textures Manually

If you prefer to load textures individually (e.g., for pre-processing), just make sure the first Animation parameter is empty so Ursina doesn’t try to load a conflicting resource:

from ursina import *
app = Ursina()
window.color = color._20

# Use a loop to load textures cleanly
coin_frames = [load_texture(f'animation/coin{i}') for i in range(1, 7)]

animation = Animation(
    '',
    fps=6,
    scale=2,
    filtering=None,
    autoplay=True,
    frames=coin_frames
)

EditorCamera()
app.run()

Quick Troubleshooting Tips

  1. File Path Clarity: If your textures have specific extensions (like .png), include them in the path (e.g., 'animation/coin1.png') to avoid ambiguity.
  2. Check Loading Status: Add print(coin_frames) after loading—any None entry means the corresponding file wasn’t found.
  3. Ensure Visibility: Temporarily set animation.position = (0,0,0) to confirm it’s not off-screen, and increase scale if needed.

内容的提问来源于stack exchange,提问作者Another_coder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:24:46