-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.ts
33 lines (28 loc) · 1.07 KB
/
object.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/// <reference path="primitives.ts" />
/// <reference path="protocols.ts" />
/// <reference path="mapobject.ts" />
namespace MapObjects {
export class Object extends MapObject implements IPlaceable,IRotateable {
position:Point;
area:Placement;
rotation:number;
rotationCenter:Point;
image: HTMLImageElement;
getFeatures() {
return [Feature.Placeable,Feature.Rotateable];
}
constructor(image:HTMLImageElement) {
super()
this.area = Placement.OnMap;
this.image = image;
this.rotationCenter = new Point(image.naturalWidth/2,image.naturalHeight/2);
}
draw(context:CanvasRenderingContext2D) {
context.drawImage(this.image,-this.image.naturalWidth/2,-this.image.naturalHeight/2);
}
hitTest(pt:Point) {
let region = new Rect(new Point(-this.image.naturalWidth/2,-this.image.naturalHeight/2),new Size(this.image.naturalWidth,this.image.naturalHeight));
return region.containsPoint(pt);
}
}
}