feat: sprite anchor

This commit is contained in:
cha0s 2024-06-22 12:12:13 -05:00
parent d94784e58e
commit 3b6aee099f
4 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
export default (type) => ({
export default (type, {x = 0, y = 0} = {}) => ({
type: 'object',
properties: {
x: {type},
y: {type},
x: {defaultValue: x, type},
y: {defaultValue: y, type},
},
});

View File

@ -1,4 +1,6 @@
import vector2d from "./helpers/vector-2d";
export default {
anchor: vector2d('float32', {x: 0.5, y: 0.5}),
animation: {type: 'string'},
elapsed: {type: 'float32'},
frame: {type: 'uint16'},

View File

@ -125,6 +125,7 @@ export default class Engine {
VisibleAabb: {},
Speed: {speed: 100},
Sprite: {
anchor: {x: 0.5, y: 0.8},
animation: 'moving:down',
frame: 0,
frames: 8,

View File

@ -17,7 +17,7 @@ export default function Sprite({entity}) {
}
return (
<PixiSprite
anchor={0.5}
anchor={entity.Sprite.anchor}
texture={texture}
x={Math.round(entity.Position.x)}
y={Math.round(entity.Position.y)}