diff --git a/app/ecs-components/helpers/vector-2d.js b/app/ecs-components/helpers/vector-2d.js index 9d0ada8..f3cda94 100644 --- a/app/ecs-components/helpers/vector-2d.js +++ b/app/ecs-components/helpers/vector-2d.js @@ -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}, }, }); diff --git a/app/ecs-components/sprite.js b/app/ecs-components/sprite.js index 8f93979..27759e8 100644 --- a/app/ecs-components/sprite.js +++ b/app/ecs-components/sprite.js @@ -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'}, diff --git a/app/engine/engine.js b/app/engine/engine.js index f1d3180..81252bf 100644 --- a/app/engine/engine.js +++ b/app/engine/engine.js @@ -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, diff --git a/app/react-components/sprite.jsx b/app/react-components/sprite.jsx index cd31a52..c57c5fb 100644 --- a/app/react-components/sprite.jsx +++ b/app/react-components/sprite.jsx @@ -17,7 +17,7 @@ export default function Sprite({entity}) { } return (