A. Importing the Ursina Library
Estimated time: 5 min | Next: B. Making a Game Window
๐ฏ Learning Goals
By the end of this lesson, you'll be able to:
- โ
from ursina import *Understand the meaning of - โ Understand what a library is
- โ Understand why we import libraries
Core Concepts
What is a library (Library)?
libraryis a collection of code that other people made in advance.
๐ Analogy: a toolbox
A library is a toolboxis the same as!
- a toolbox that holds a hammer, screwdriver, saw, and so on
- You just take out the tool you need and use it
- Use it right away โ no need to build your own tools!
The Ursina library comes packed with tools for making 3D games!
import flowchart
flowchart TD
A["from ursina import *"] --> B["Load the Ursina library"]
B --> C["Entity, color, Vec3, and more<br/>all features available!"]
C --> D["Start 3D game development"]
style A fill:#e3f2fd,stroke:#1976d2
style B fill:#fff3e0,stroke:#f57c00
style C fill:#e8f5e9,stroke:#388e3c
style D fill:#f3e5f5,stroke:#7b1fa2
Comparison of major libraries
| library | Use | Example |
|---|---|---|
| Math calculations | sqrt(), sin() |
|
| 2D graphics | Turtle drawing | |
| 3D game development | Cubes, characters |
Writing the code
Description:
from ursina: From the Ursina libraryimport *: Import all features*means "everything"
โ ๏ธ Order matters!
from ursina import *always goes at the Top of the fileof your code!
Without this line, you can't use any of Ursina's features.
Example Code
from ursina import * # Import all of Ursina's features
# Now you can use Ursina(), Entity(), color, and more!
Result
Thanks to this line, you get access to 3D game features!
๐ฏ Quiz
from ursina import *in * โ what does it mean?
Show Answer
Answer: C) It means importing all features
* is a wildcard that means "everything."
from ursina import * imports all of the Ursina library's features!
๐ง Debug Clinic
Problem: NameError: name 'Ursina' is not defined
Cause: from ursina import *: you didn't write it or there's a typo
Fix: At the very top of the file, from ursina import * Add
Problem: ModuleNotFoundError: No module named 'ursina'
Cause: Ursina isn't installed
Fix: Run the install command in the terminal
Try Coding It Yourself
Try writing the code to import the Ursina library yourself!
Writing an import statement
Fill in the blank with the correct import statement.
Example Answer
Description: This one line gives you access to all of Ursina's 3D game features!
๐งฉ Key Takeaways
What you learned in this lesson:
- library: A collection of ready-made code (a toolbox)
- import: The command to import a library
*: Means "everything" (a wildcard)- Position: Always at the very top of the file!
Review Checklist
- [ ] Can you explain what a library is?
- [ ]
from ursina import *Do you understand what it means? - [ ] Do you know where in the file the import statement should go?
Next step: B. Making a Game Window โ