avocado-old/packages/graphics/renderable.js

115 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-03-30 05:07:21 -05:00
import {compose} from '@avocado/core';
import {EventEmitter} from '@avocado/mixins';
const decorate = compose(
EventEmitter,
);
export class Renderable extends decorate(class {}) {
2019-03-18 20:06:47 -05:00
constructor() {
2019-03-30 05:07:21 -05:00
super();
this.parent = null;
this._zIndex = 0;
}
2019-04-19 16:23:26 -05:00
destroy() {
if (this.internal) {
this.internal.destroy();
delete this.internal;
}
}
2019-03-18 20:06:47 -05:00
get alpha() {
return this.internal.alpha;
}
set alpha(alpha) {
this.internal.alpha = alpha;
}
2019-04-19 16:23:26 -05:00
get anchor() {
const anchor = this.internal.anchor || {x: 0, y: 0};
return [
anchor.x,
anchor.y,
];
}
set anchor(anchor) {
this.internal.anchor = {
x: anchor[0],
y: anchor[1],
};
2019-03-19 18:29:11 -05:00
}
2019-03-18 20:06:47 -05:00
get position() {
return [this.internal.x, this.internal.y];
}
set position(position) {
this.internal.x = position[0];
this.internal.y = position[1];
}
get rotation() {
return this.internal.rotation;
}
set rotation(rotation) {
this.internal.rotation = rotation;
}
2019-03-25 18:55:06 -05:00
get scale() {
const scale = this.internal.scale || {x: 1, y: 1};
return [
scale.x,
scale.y,
];
}
set scale(scale) {
this.internal.scale = {
x: scale[0],
2019-04-19 16:23:26 -05:00
y: scale[1],
2019-03-25 18:55:06 -05:00
};
}
2019-03-18 20:06:47 -05:00
get visible() {
return this.internal.visible;
}
set visible(isVisible) {
this.internal.visible = isVisible;
}
get x() {
return this.internal.x;
}
set x(x) {
this.internal.x = x;
}
get y() {
return this.internal.y;
}
set y(y) {
this.internal.y = y;
}
get zIndex() {
return this._zIndex;
}
set zIndex(zIndex) {
if (this.parent) {
this.parent.isDirty = true;
}
this._zIndex = zIndex;
}
2019-03-18 20:06:47 -05:00
}