AreaMap Component
Component used by Mouse and Touch. Can be added to other entities for use with the Crafty.findPointerEventTargetByComponent method.
Methods
Back to top
.areaMap()
Events
- NewAreaMap [Data = {Crafty.polygon}]
- when a new areaMap is assigned
public this .areaMap(Crafty.polygon polygon)
- polygon
Instance of Crafty.polygon used to check if the mouse coordinates are inside this region
public this .areaMap(Array coordinatePairs)
- coordinatePairs
Array of
x
,y
coordinate pairs to generate a polygon
public this .areaMap(x1, y1,.., xN, yN)
- point#
List of
x
,y
coordinate pairs to generate a polygon
Assign a polygon to the entity so that pointer (mouse or touch) events will only be triggered if the coordinates are inside the given polygon.
Example
Crafty.e("2D, DOM, Color, Mouse")
.color("red")
.attr({ w: 100, h: 100 })
.bind('MouseOver', function() {Crafty.log("over")})
.areaMap(0, 0, 50, 0, 50, 50, 0, 50);
Crafty.e("2D, Mouse")
.areaMap([0, 0, 50, 0, 50, 50, 0, 50]);
Crafty.e("2D, Mouse").areaMap(
new Crafty.polygon([0, 0, 50, 0, 50, 50, 0, 50])
);