@icanvas/components
Version:
这是icanvas的界面组件包
38 lines (37 loc) • 869 B
JavaScript
import Component from './base.js';
import Canvas from '@icanvas/apis/libs/canvas.js';
export default class Cache extends Component {
context = Canvas().getContext('2d');
get width() {
return this.context.canvas.width;
}
get height() {
return this.context.canvas.height;
}
get canvas() {
return this.context.canvas;
}
constructor(width, height) {
super();
this.setSize(width, height);
}
setSize(x, y) {
this.context.SetSize(x, y);
return this;
}
setAnchorSize(x = 0.5, y = 0.5) {
this.anchor.x = this.width * x;
this.anchor.y = this.height * y;
return this;
}
setStatic(callback) {
callback.call(this, this.context);
return this;
}
update(Context) {
Context.drawImage(this.canvas, -this.anchor.x, -this.anchor.y, this.width, this.height);
}
hitMe(x, y) {
return x >= 0 && x <= this.width && y >= 0 && y <= this.height;
}
}