avocado-old/packages/graphics/renderable.js
2019-03-30 05:07:21 -05:00

100 lines
1.5 KiB
JavaScript

import {compose} from '@avocado/core';
import {EventEmitter} from '@avocado/mixins';
const decorate = compose(
EventEmitter,
);
export class Renderable extends decorate(class {}) {
constructor() {
super();
this.parent = null;
this._zIndex = 0;
}
get alpha() {
return this.internal.alpha;
}
set alpha(alpha) {
this.internal.alpha = alpha;
}
destroy() {
if (this.internal) {
this.internal.destroy();
delete this.internal;
}
}
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;
}
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],
y: scale[1]
};
}
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;
}
}