Y-Axis rendering #3
Labels
No labels
Breaking
Bug
Documentation
Enhancement
Feature
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Security
Status
Abandoned
Status
Blocked
Status
Need More Info
Testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Wiener234/game#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Render the sprites sorted by y-Axis. A higher y-axis gets rendered on top.
To sort a list of sprites (or entities) by their Y-axis, you need a clear and consistent data structure for your entities/sprites and a strategy to organize them in a list that can be sorted. Here's a straightforward way to approach this in C:
1. Define a Struct for Sprites/Entities
If your entities and sprites are different but both need to be sorted visually, they should share at least a common base: the Y-position.
You can either:
Here’s a possible struct definition:
2. Define a Renderable Struct
To sort both
EntityandSprite, you can wrap them in a common type:3. Populate the Renderable Array
You create an array of
Renderableitems before rendering, and cache theiryposition for sorting:4. Sort the List by Y
You can use
qsort()from the C standard library:5. Render in Sorted Order
After sorting:
Summary
Renderablewrapper struct to unify entities/sprites for sortingyposition to avoid multiple dereferencesqsort()and a float comparisonIf your use case is more specific or you're using a library like raylib, let me know — I can tailor the solution to that.