Comments (5)
@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.
We could also expose offset
in the actor constructor?
from excalibur.
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.
Good points, also it should totally account for the scale that's definitely a bug
from excalibur.
This issue hasn't had any recent activity lately and is being marked as stale automatically.
from excalibur.
Related Issues (20)
- Scaled spritefont is badly rendering font HOT 4
- Docs: Improve documentation for shaders HOT 1
- Docs: improve documentation for graphics HOT 1
- Typescript definition for font blur has optional property offset, but it is required HOT 1
- Docs: improve loader documentation HOT 1
- Error when child w/ transform + graphics component is added to entity without transform component HOT 2
- Pause/unpause Actors and Entities feature
- scaleTo/scaleBy doesn't work with simultaneous axes
- lastWorldPos should update when camera moves under pointer
- The native pointer cancel event does not seem to bubble into excalibur
- Support mouseOut/pointerOut style event when the cursor leaves the game canvas
- Improving custom event DX HOT 1
- Children of entity doesn't inherit z or opacity HOT 3
- New API actions.parallel HOT 1
- Docs: fix and/or update GraphicsGroup documentation HOT 1
- Support Uniform Buffer Objects in Materials and Postprocessors
- Transition `blockInput: true` only works on input events
- Add option to ActionsComponent to cancel currently executing actions on collision
- docs: Actions with collisions
- Fast fadeBy action doesn't sometimes complete (probably under stress) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from excalibur.