feat: animation offset

This commit is contained in:
cha0s 2019-03-19 21:11:04 -05:00
parent fff621be50
commit 7902311131

View File

@ -54,7 +54,7 @@ class AnimatedBase extends Trait {
const animationPromises = [];
// Load all animations.
for (const key in animations) {
const uri = animations[key];
const {uri} = animations[key];
const promise = Animation.load(uri).then((animation) => {
// Zip with key to make populating animations and views trivial.
return {animation, key};
@ -109,10 +109,12 @@ class AnimatedBase extends Trait {
if (!animationView) {
return;
}
const animations = this.params.get('animations');
const {offset} = animations[key];
const {animation} = animationView;
const size = Rectangle.size(animation.sourceRectangle)
const offset = Vector.scale(size, -0.5);
animationView.position = offset;
const halfway = Vector.scale(size, -0.5);
animationView.position = Vector.add(halfway, offset);
this.entity.container.addChild(animationView);
}