Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Sprites currently have their origin fixed at the center of their costume. This adds the ability to set the origin to one of nine preset positions or a custom offset, affecting position, rotation, and hitbox calculations.

Changes

  • New Origin enum with 10 values: TOP_LEFT, TOP_CENTER, TOP_RIGHT, CENTER_LEFT, CENTER, CENTER_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT, and CUSTOM
  • Sprite API additions:
    • setOrigin(Origin origin) - preset position
    • setOrigin(double x, double y) - custom offset from center
    • getOrigin(), getOriginX(), getOriginY() - getters
  • Updated rendering pipeline: Image.draw(), Stamp.draw(), and hitbox calculation now account for origin offset
  • Debug mode visualization: When an origin offset is set, debug mode displays the offset values, a line from the sprite position to the image center, a cross marker at the origin point, and a circle at the image center
  • Reference examples: SpriteSetOrigin.java, SpriteGetOrigin.java

Usage

Sprite sprite = new Sprite("player", "player.png");

// Preset origin
sprite.setOrigin(Origin.TOP_LEFT);

// Custom offset: 50px left and 50px down from center
sprite.setOrigin(-50, -50);

Preset origins calculate offset dynamically based on sprite dimensions. Custom origins store the exact offset values.

Original prompt

I want sprite to have an origin. Currently their origin is in the center of their costume. But I want that one can set the Origin to one of nine relative positions. Topleft, topcenter, topright,... or to a custom position, which should be relative to the center. So setOrigin(-50,-50) would offset the origin 50 pixels to the left and 50 pixels to the bottom from the center (0,0). This should have an effect on the position of the sprite and on their rotation and on other things, which i might forgot.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 31, 2025
Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add configurable origin positions for sprites Add sprite origin support with preset and custom positions Dec 31, 2025
Copilot AI requested a review from mikebarkmin December 31, 2025 11:09
@mikebarkmin
Copy link
Member

@copilot The offset should also be visible in the debug mode.

Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot The offset should also be visible in the debug mode.

Added debug mode visualization in commit 1055358. When an origin offset is set, debug mode now shows:

  • Text displaying the origin offset values
  • A line from the sprite position to the image center
  • A cross marker at the origin point (sprite position)
  • A circle at the image center position

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants