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', type: 'object',
properties: { properties: {
x: {type}, x: {defaultValue: x, type},
y: {type}, y: {defaultValue: y, type},
}, },
}); });

View File

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

View File

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

View File

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