Git Product home page Git Product logo

Comments (5)

eonarheim avatar eonarheim commented on June 8, 2024

@mattjennings I agree! I think a pixel offset is useful in this case. Let me play around with the first one, a ex.Anchor type that extends vector would be a relatively easy drop in.

We do have a way to do this (but not super visible on actor). On the graphics component we have a actor.graphics.offset property that will shift graphics by pixels.

const actor = new ex.Actor({...});
actor.graphics.anchor = ex.vec(0, 0); // zero out the anchor
actor.graphics.offset = ex.vec(-8, -8); // offset 

Internally this is the drawing code in GraphicsSystem

    let anchor = graphicsComponent.anchor;
    let offset = graphicsComponent.offset;

    // handle specific overrides
    if (options?.anchor) {
      anchor = options.anchor;
    }
    if (options?.offset) {
      offset = options.offset;
    }
    // See https://github.com/excaliburjs/Excalibur/pull/619 for discussion on this formula
    const offsetX = -graphic.width * anchor.x + offset.x;
    const offsetY = -graphic.height * anchor.y + offset.y;

    const oldFlipHorizontal = graphic.flipHorizontal;
    const oldFlipVertical = graphic.flipVertical;
    if (flipHorizontal || flipVertical) {
      // flip any currently flipped graphics
      graphic.flipHorizontal = flipHorizontal ? !oldFlipHorizontal : oldFlipHorizontal;
      graphic.flipVertical = flipVertical ? !oldFlipVertical : oldFlipVertical;
    }

    graphic?.draw(
      this._graphicsContext,
      offsetX,
      offsetY);

from excalibur.

eonarheim avatar eonarheim commented on June 8, 2024

We could also expose offset in the actor constructor?

from excalibur.

mattjennings avatar mattjennings commented on June 8, 2024

I actually did try using the offset on the graphics initially (and I do think it's worth exposing that on the actor constructor), but it wasn't quite the same thing as adjusting the anchor. For example, when I applied a scale it still scaled according to the anchor point. I suppose the scale effect could account for this, but I think that's more a symptom of the issue.

from excalibur.

eonarheim avatar eonarheim commented on June 8, 2024

Good points, also it should totally account for the scale that's definitely a bug

from excalibur.

github-actions avatar github-actions commented on June 8, 2024

This issue hasn't had any recent activity lately and is being marked as stale automatically.

from excalibur.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.