新增虚拟输入类 VirtualInput
This commit is contained in:
Vendored
+260
-139
@@ -285,7 +285,6 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
setUpdateOrder(updateOrder: number): this;
|
setUpdateOrder(updateOrder: number): this;
|
||||||
clone(): Component;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -334,7 +333,6 @@ declare module es {
|
|||||||
destroy(): void;
|
destroy(): void;
|
||||||
detachFromScene(): void;
|
detachFromScene(): void;
|
||||||
attachToScene(newScene: Scene): void;
|
attachToScene(newScene: Scene): void;
|
||||||
clone(position?: Vector2): Entity;
|
|
||||||
onAddedToScene(): void;
|
onAddedToScene(): void;
|
||||||
onRemovedFromScene(): void;
|
onRemovedFromScene(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
@@ -349,7 +347,6 @@ declare module es {
|
|||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
compareTo(other: Entity): number;
|
compareTo(other: Entity): number;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
protected copyFrom(entity: Entity): void;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -691,7 +688,7 @@ declare module es {
|
|||||||
class SpriteAnimation {
|
class SpriteAnimation {
|
||||||
readonly sprites: Sprite[];
|
readonly sprites: Sprite[];
|
||||||
readonly frameRate: number;
|
readonly frameRate: number;
|
||||||
constructor(sprites: Sprite[], frameRate: number);
|
constructor(sprites: Sprite[], frameRate?: number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -759,7 +756,7 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class TiledMapRenderer extends RenderableComponent {
|
class TiledMapRenderer extends RenderableComponent {
|
||||||
tiledMap: TmxMap;
|
tiledMap: TmxMap;
|
||||||
physicsLayer: number;
|
physicsLayer: Ref<number>;
|
||||||
layerIndicesToRender: number[];
|
layerIndicesToRender: number[];
|
||||||
private toContainer;
|
private toContainer;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
@@ -808,11 +805,10 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class Collider extends Component {
|
abstract class Collider extends Component {
|
||||||
debug: any;
|
|
||||||
shape: Shape;
|
shape: Shape;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
physicsLayer: number;
|
physicsLayer: Ref<number>;
|
||||||
collidesWithLayers: number;
|
collidesWithLayers: Ref<number>;
|
||||||
shouldColliderScaleAndRotateWithTransform: boolean;
|
shouldColliderScaleAndRotateWithTransform: boolean;
|
||||||
registeredPhysicsBounds: Rectangle;
|
registeredPhysicsBounds: Rectangle;
|
||||||
_localOffsetLength: number;
|
_localOffsetLength: number;
|
||||||
@@ -837,7 +833,6 @@ declare module es {
|
|||||||
unregisterColliderWithPhysicsSystem(): void;
|
unregisterColliderWithPhysicsSystem(): void;
|
||||||
overlaps(other: Collider): boolean;
|
overlaps(other: Collider): boolean;
|
||||||
collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
|
collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
|
||||||
clone(): Component;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -846,10 +841,9 @@ declare module es {
|
|||||||
polygonShape: egret.Shape;
|
polygonShape: egret.Shape;
|
||||||
pixelShape1: egret.Shape;
|
pixelShape1: egret.Shape;
|
||||||
pixelShape2: egret.Shape;
|
pixelShape2: egret.Shape;
|
||||||
constructor();
|
constructor(x?: number, y?: number, width?: number, height?: number);
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
createBoxRect(x: number, y: number, width: number, height: number): BoxCollider;
|
|
||||||
setSize(width: number, height: number): this;
|
setSize(width: number, height: number): this;
|
||||||
setWidth(width: number): BoxCollider;
|
setWidth(width: number): BoxCollider;
|
||||||
setHeight(height: number): void;
|
setHeight(height: number): void;
|
||||||
@@ -1303,10 +1297,10 @@ declare module es {
|
|||||||
class Flags {
|
class Flags {
|
||||||
static isFlagSet(self: number, flag: number): boolean;
|
static isFlagSet(self: number, flag: number): boolean;
|
||||||
static isUnshiftedFlagSet(self: number, flag: number): boolean;
|
static isUnshiftedFlagSet(self: number, flag: number): boolean;
|
||||||
static setFlagExclusive(self: number, flag: number): number;
|
static setFlagExclusive(self: Ref<number>, flag: number): void;
|
||||||
static setFlag(self: number, flag: number): number;
|
static setFlag(self: Ref<number>, flag: number): void;
|
||||||
static unsetFlag(self: number, flag: number): number;
|
static unsetFlag(self: Ref<number>, flag: number): void;
|
||||||
static invertFlags(self: number): number;
|
static invertFlags(self: Ref<number>): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1422,12 +1416,12 @@ declare module es {
|
|||||||
static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
|
static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
|
||||||
static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
|
static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
|
||||||
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
||||||
static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
|
static circleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
|
||||||
static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
|
static circleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
|
||||||
static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
|
static circleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
|
||||||
static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
|
static rectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
|
||||||
static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
|
static rectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
|
||||||
static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
|
static rectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
|
||||||
static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
|
static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1486,7 +1480,6 @@ declare module es {
|
|||||||
abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
|
abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
|
||||||
abstract containsPoint(point: Vector2): any;
|
abstract containsPoint(point: Vector2): any;
|
||||||
abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
||||||
clone(): Shape;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1508,7 +1501,7 @@ declare module es {
|
|||||||
static findPolygonCenter(points: Vector2[]): Vector2;
|
static findPolygonCenter(points: Vector2[]): Vector2;
|
||||||
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
||||||
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref<number>, edgeNormal: Vector2): Vector2;
|
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref<number>, edgeNormal: Vector2): Vector2;
|
||||||
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]): void;
|
||||||
recalculateBounds(collider: Collider): void;
|
recalculateBounds(collider: Collider): void;
|
||||||
overlaps(other: Shape): any;
|
overlaps(other: Shape): any;
|
||||||
collidesWithShape(other: Shape, result: CollisionResult): boolean;
|
collidesWithShape(other: Shape, result: CollisionResult): boolean;
|
||||||
@@ -2051,122 +2044,6 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class TouchState {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
touchPoint: number;
|
|
||||||
touchDown: boolean;
|
|
||||||
readonly position: Vector2;
|
|
||||||
reset(): void;
|
|
||||||
}
|
|
||||||
class Input {
|
|
||||||
private static _init;
|
|
||||||
private static _previousTouchState;
|
|
||||||
private static _resolutionOffset;
|
|
||||||
private static _touchIndex;
|
|
||||||
private static _gameTouchs;
|
|
||||||
static readonly gameTouchs: TouchState[];
|
|
||||||
private static _resolutionScale;
|
|
||||||
static readonly resolutionScale: Vector2;
|
|
||||||
private static _totalTouchCount;
|
|
||||||
static readonly totalTouchCount: number;
|
|
||||||
static readonly touchPosition: Vector2;
|
|
||||||
static maxSupportedTouch: number;
|
|
||||||
static readonly touchPositionDelta: Vector2;
|
|
||||||
static initialize(): void;
|
|
||||||
static scaledPosition(position: Vector2): Vector2;
|
|
||||||
private static initTouchCache;
|
|
||||||
private static touchBegin;
|
|
||||||
private static touchMove;
|
|
||||||
private static touchEnd;
|
|
||||||
private static setpreviousTouchState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare class KeyboardUtils {
|
|
||||||
static TYPE_KEY_DOWN: number;
|
|
||||||
static TYPE_KEY_UP: number;
|
|
||||||
static A: string;
|
|
||||||
static B: string;
|
|
||||||
static C: string;
|
|
||||||
static D: string;
|
|
||||||
static E: string;
|
|
||||||
static F: string;
|
|
||||||
static G: string;
|
|
||||||
static H: string;
|
|
||||||
static I: string;
|
|
||||||
static J: string;
|
|
||||||
static K: string;
|
|
||||||
static L: string;
|
|
||||||
static M: string;
|
|
||||||
static N: string;
|
|
||||||
static O: string;
|
|
||||||
static P: string;
|
|
||||||
static Q: string;
|
|
||||||
static R: string;
|
|
||||||
static S: string;
|
|
||||||
static T: string;
|
|
||||||
static U: string;
|
|
||||||
static V: string;
|
|
||||||
static W: string;
|
|
||||||
static X: string;
|
|
||||||
static Y: string;
|
|
||||||
static Z: string;
|
|
||||||
static ESC: string;
|
|
||||||
static F1: string;
|
|
||||||
static F2: string;
|
|
||||||
static F3: string;
|
|
||||||
static F4: string;
|
|
||||||
static F5: string;
|
|
||||||
static F6: string;
|
|
||||||
static F7: string;
|
|
||||||
static F8: string;
|
|
||||||
static F9: string;
|
|
||||||
static F10: string;
|
|
||||||
static F11: string;
|
|
||||||
static F12: string;
|
|
||||||
static NUM_1: string;
|
|
||||||
static NUM_2: string;
|
|
||||||
static NUM_3: string;
|
|
||||||
static NUM_4: string;
|
|
||||||
static NUM_5: string;
|
|
||||||
static NUM_6: string;
|
|
||||||
static NUM_7: string;
|
|
||||||
static NUM_8: string;
|
|
||||||
static NUM_9: string;
|
|
||||||
static NUM_0: string;
|
|
||||||
static TAB: string;
|
|
||||||
static CTRL: string;
|
|
||||||
static ALT: string;
|
|
||||||
static SHIFT: string;
|
|
||||||
static CAPS_LOCK: string;
|
|
||||||
static ENTER: string;
|
|
||||||
static SPACE: string;
|
|
||||||
static BACK_SPACE: string;
|
|
||||||
static INSERT: string;
|
|
||||||
static DELETE: string;
|
|
||||||
static HOME: string;
|
|
||||||
static END: string;
|
|
||||||
static PAGE_UP: string;
|
|
||||||
static PAGE_DOWN: string;
|
|
||||||
static LEFT: string;
|
|
||||||
static RIGHT: string;
|
|
||||||
static UP: string;
|
|
||||||
static DOWN: string;
|
|
||||||
static PAUSE_BREAK: string;
|
|
||||||
static NUM_LOCK: string;
|
|
||||||
static SCROLL_LOCK: string;
|
|
||||||
static WINDOWS: string;
|
|
||||||
private static keyDownDict;
|
|
||||||
private static keyUpDict;
|
|
||||||
static init(): void;
|
|
||||||
static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
|
|
||||||
static unregisterKey(key: string, type?: number): void;
|
|
||||||
static destroy(): void;
|
|
||||||
private static onKeyDonwHander;
|
|
||||||
private static onKeyUpHander;
|
|
||||||
private static keyCodeToString;
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
class ListPool {
|
class ListPool {
|
||||||
private static readonly _objectQueue;
|
private static readonly _objectQueue;
|
||||||
@@ -2386,6 +2263,250 @@ declare module es {
|
|||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TouchState {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
touchPoint: number;
|
||||||
|
touchDown: boolean;
|
||||||
|
readonly position: Vector2;
|
||||||
|
reset(): void;
|
||||||
|
}
|
||||||
|
class Input {
|
||||||
|
private static _init;
|
||||||
|
private static _previousTouchState;
|
||||||
|
private static _resolutionOffset;
|
||||||
|
private static _touchIndex;
|
||||||
|
private static _gameTouchs;
|
||||||
|
static readonly gameTouchs: TouchState[];
|
||||||
|
private static _resolutionScale;
|
||||||
|
static readonly resolutionScale: Vector2;
|
||||||
|
private static _totalTouchCount;
|
||||||
|
static readonly totalTouchCount: number;
|
||||||
|
static readonly touchPosition: Vector2;
|
||||||
|
static _virtualInputs: VirtualInput[];
|
||||||
|
static maxSupportedTouch: number;
|
||||||
|
static readonly touchPositionDelta: Vector2;
|
||||||
|
static initialize(): void;
|
||||||
|
static update(): void;
|
||||||
|
static scaledPosition(position: Vector2): Vector2;
|
||||||
|
static isKeyPressed(key: Keys): boolean;
|
||||||
|
static isKeyPressedBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
static isKeyDown(key: Keys): boolean;
|
||||||
|
static isKeyDownBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
static isKeyReleased(key: Keys): boolean;
|
||||||
|
static isKeyReleasedBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
private static initTouchCache;
|
||||||
|
private static touchBegin;
|
||||||
|
private static touchMove;
|
||||||
|
private static touchEnd;
|
||||||
|
private static setpreviousTouchState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
import Keys = es.Keys;
|
||||||
|
declare class KeyboardUtils {
|
||||||
|
static currentKeys: Keys[];
|
||||||
|
static previousKeys: Keys[];
|
||||||
|
private static keyStatusKeys;
|
||||||
|
static init(): void;
|
||||||
|
static update(): void;
|
||||||
|
static destroy(): void;
|
||||||
|
private static onKeyDownHandler;
|
||||||
|
private static onKeyUpHandler;
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
enum Keys {
|
||||||
|
none = 0,
|
||||||
|
back = 8,
|
||||||
|
tab = 9,
|
||||||
|
enter = 13,
|
||||||
|
capsLock = 20,
|
||||||
|
escape = 27,
|
||||||
|
space = 32,
|
||||||
|
pageUp = 33,
|
||||||
|
pageDown = 34,
|
||||||
|
end = 35,
|
||||||
|
home = 36,
|
||||||
|
left = 37,
|
||||||
|
up = 38,
|
||||||
|
right = 39,
|
||||||
|
down = 40,
|
||||||
|
select = 41,
|
||||||
|
print = 42,
|
||||||
|
execute = 43,
|
||||||
|
printScreen = 44,
|
||||||
|
insert = 45,
|
||||||
|
delete = 46,
|
||||||
|
help = 47,
|
||||||
|
d0 = 48,
|
||||||
|
d1 = 49,
|
||||||
|
d2 = 50,
|
||||||
|
d3 = 51,
|
||||||
|
d4 = 52,
|
||||||
|
d5 = 53,
|
||||||
|
d6 = 54,
|
||||||
|
d7 = 55,
|
||||||
|
d8 = 56,
|
||||||
|
d9 = 57,
|
||||||
|
a = 65,
|
||||||
|
b = 66,
|
||||||
|
c = 67,
|
||||||
|
d = 68,
|
||||||
|
e = 69,
|
||||||
|
f = 70,
|
||||||
|
g = 71,
|
||||||
|
h = 72,
|
||||||
|
i = 73,
|
||||||
|
j = 74,
|
||||||
|
k = 75,
|
||||||
|
l = 76,
|
||||||
|
m = 77,
|
||||||
|
n = 78,
|
||||||
|
o = 79,
|
||||||
|
p = 80,
|
||||||
|
q = 81,
|
||||||
|
r = 82,
|
||||||
|
s = 83,
|
||||||
|
t = 84,
|
||||||
|
u = 85,
|
||||||
|
v = 86,
|
||||||
|
w = 87,
|
||||||
|
x = 88,
|
||||||
|
y = 89,
|
||||||
|
z = 90,
|
||||||
|
leftWindows = 91,
|
||||||
|
rightWindows = 92,
|
||||||
|
apps = 93,
|
||||||
|
sleep = 95,
|
||||||
|
numPad0 = 96,
|
||||||
|
numPad1 = 97,
|
||||||
|
numPad2 = 98,
|
||||||
|
numPad3 = 99,
|
||||||
|
numPad4 = 100,
|
||||||
|
numPad5 = 101,
|
||||||
|
numPad6 = 102,
|
||||||
|
numPad7 = 103,
|
||||||
|
numPad8 = 104,
|
||||||
|
numPad9 = 105,
|
||||||
|
multiply = 106,
|
||||||
|
add = 107,
|
||||||
|
seperator = 108,
|
||||||
|
subtract = 109,
|
||||||
|
decimal = 110,
|
||||||
|
divide = 111,
|
||||||
|
f1 = 112,
|
||||||
|
f2 = 113,
|
||||||
|
f3 = 114,
|
||||||
|
f4 = 115,
|
||||||
|
f5 = 116,
|
||||||
|
f6 = 117,
|
||||||
|
f7 = 118,
|
||||||
|
f8 = 119,
|
||||||
|
f9 = 120,
|
||||||
|
f10 = 121,
|
||||||
|
f11 = 122,
|
||||||
|
f12 = 123,
|
||||||
|
f13 = 124,
|
||||||
|
f14 = 125,
|
||||||
|
f15 = 126,
|
||||||
|
f16 = 127,
|
||||||
|
f17 = 128,
|
||||||
|
f18 = 129,
|
||||||
|
f19 = 130,
|
||||||
|
f20 = 131,
|
||||||
|
f21 = 132,
|
||||||
|
f22 = 133,
|
||||||
|
f23 = 134,
|
||||||
|
f24 = 135,
|
||||||
|
numLock = 144,
|
||||||
|
scroll = 145,
|
||||||
|
leftShift = 160,
|
||||||
|
rightShift = 161,
|
||||||
|
leftControl = 162,
|
||||||
|
rightControl = 163,
|
||||||
|
leftAlt = 164,
|
||||||
|
rightAlt = 165,
|
||||||
|
browserBack = 166,
|
||||||
|
browserForward = 167
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
enum OverlapBehavior {
|
||||||
|
cancelOut = 0,
|
||||||
|
takeOlder = 1,
|
||||||
|
takeNewer = 2
|
||||||
|
}
|
||||||
|
abstract class VirtualInput {
|
||||||
|
protected constructor();
|
||||||
|
deregister(): void;
|
||||||
|
abstract update(): any;
|
||||||
|
}
|
||||||
|
abstract class VirtualInputNode {
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualIntegerAxis extends VirtualInput {
|
||||||
|
nodes: VirtualAxisNode[];
|
||||||
|
readonly value: number;
|
||||||
|
constructor(...nodes: VirtualAxisNode[]);
|
||||||
|
update(): void;
|
||||||
|
addKeyboardKeys(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys): this;
|
||||||
|
}
|
||||||
|
abstract class VirtualAxisNode extends VirtualInputNode {
|
||||||
|
abstract value: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualAxis extends VirtualInput {
|
||||||
|
nodes: VirtualAxisNode[];
|
||||||
|
readonly value: number;
|
||||||
|
constructor(...nodes: VirtualAxisNode[]);
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
class KeyboardKeys extends VirtualAxisNode {
|
||||||
|
overlapBehavior: OverlapBehavior;
|
||||||
|
positive: Keys;
|
||||||
|
negative: Keys;
|
||||||
|
_value: number;
|
||||||
|
_turned: boolean;
|
||||||
|
constructor(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys);
|
||||||
|
update(): void;
|
||||||
|
readonly value: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualButton extends VirtualInput {
|
||||||
|
nodes: Node[];
|
||||||
|
bufferTime: number;
|
||||||
|
firstRepeatTime: number;
|
||||||
|
mutiRepeatTime: number;
|
||||||
|
isRepeating: boolean;
|
||||||
|
_bufferCounter: number;
|
||||||
|
_repeatCounter: number;
|
||||||
|
_willRepeat: boolean;
|
||||||
|
constructor(bufferTime?: number, ...nodes: Node[]);
|
||||||
|
setRepeat(firstRepeatTime: number, mutiRepeatTime?: number): void;
|
||||||
|
update(): void;
|
||||||
|
readonly isDown: boolean;
|
||||||
|
readonly isPressed: boolean;
|
||||||
|
readonly isReleased: boolean;
|
||||||
|
consumeBuffer(): void;
|
||||||
|
addKeyboardKey(key: Keys): VirtualButton;
|
||||||
|
}
|
||||||
|
abstract class Node extends VirtualInputNode {
|
||||||
|
abstract isDown: boolean;
|
||||||
|
abstract isPressed: boolean;
|
||||||
|
abstract isReleased: boolean;
|
||||||
|
}
|
||||||
|
class KeyboardKey extends Node {
|
||||||
|
key: Keys;
|
||||||
|
constructor(key: Keys);
|
||||||
|
readonly isDown: boolean;
|
||||||
|
readonly isPressed: boolean;
|
||||||
|
readonly isReleased: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class AssetPacker {
|
class AssetPacker {
|
||||||
protected itemsToRaster: TextureToPack[];
|
protected itemsToRaster: TextureToPack[];
|
||||||
|
|||||||
+734
-449
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+3
-1
@@ -17,7 +17,7 @@
|
|||||||
"bin-debug/SampleHelpers/SampleScene.js",
|
"bin-debug/SampleHelpers/SampleScene.js",
|
||||||
"bin-debug/Scenes/Ninja Adventure/ProjectileHitDetector.js",
|
"bin-debug/Scenes/Ninja Adventure/ProjectileHitDetector.js",
|
||||||
"bin-debug/UI/loading/LoadingView.js",
|
"bin-debug/UI/loading/LoadingView.js",
|
||||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
"bin-debug/Scenes/Ninja Adventure/CameraBounds.js",
|
||||||
"bin-debug/Fgui/loading/loadingBinder.js",
|
"bin-debug/Fgui/loading/loadingBinder.js",
|
||||||
"bin-debug/Fgui/loading/UI_View_loading.js",
|
"bin-debug/Fgui/loading/UI_View_loading.js",
|
||||||
"bin-debug/Fgui/sc/scBinder.js",
|
"bin-debug/Fgui/sc/scBinder.js",
|
||||||
@@ -28,7 +28,9 @@
|
|||||||
"bin-debug/Scenes/Animated Tiles/AnimatedTilesScene.js",
|
"bin-debug/Scenes/Animated Tiles/AnimatedTilesScene.js",
|
||||||
"bin-debug/Scenes/Empty Scene/BasicScene.js",
|
"bin-debug/Scenes/Empty Scene/BasicScene.js",
|
||||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
||||||
|
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||||
"bin-debug/Main.js",
|
"bin-debug/Main.js",
|
||||||
|
"bin-debug/Scenes/Ninja Adventure/FireballProjectileController.js",
|
||||||
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
|
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
|
||||||
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
|
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
|
||||||
"bin-debug/ThemeAdapter.js",
|
"bin-debug/ThemeAdapter.js",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"groups": [
|
"groups": [
|
||||||
{
|
{
|
||||||
"keys": "bg_png,bgNorm_png,moon_png,orange_png,moonNorm_png,orangeNorm_png,orthogonal-outside_json",
|
"keys": "bg_png,bgNorm_png,moon_png,orange_png,moonNorm_png,orangeNorm_png,tiledMap_json,orthogonal-outside_json,tilemap_json,plume_png",
|
||||||
"name": "preload"
|
"name": "preload"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -52,11 +52,6 @@
|
|||||||
"type": "image",
|
"type": "image",
|
||||||
"name": "orangeNorm_png"
|
"name": "orangeNorm_png"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"url": "preload/orthogonal-outside.json",
|
|
||||||
"type": "json",
|
|
||||||
"name": "orthogonal-outside_json"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"url": "characters/1.png",
|
"url": "characters/1.png",
|
||||||
"type": "image",
|
"type": "image",
|
||||||
@@ -101,6 +96,26 @@
|
|||||||
"url": "fgui/loading.zip",
|
"url": "fgui/loading.zip",
|
||||||
"type": "bin",
|
"type": "bin",
|
||||||
"name": "loading"
|
"name": "loading"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "preload/caveman/tiledMap.json",
|
||||||
|
"type": "json",
|
||||||
|
"name": "tiledMap_json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "preload/orthogonal/orthogonal-outside.json",
|
||||||
|
"type": "json",
|
||||||
|
"name": "orthogonal-outside_json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "preload/ninja/tilemap.json",
|
||||||
|
"type": "json",
|
||||||
|
"name": "tilemap_json"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "preload/plume.png",
|
||||||
|
"type": "image",
|
||||||
|
"name": "plume_png"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,193 @@
|
|||||||
|
{ "height":30,
|
||||||
|
"infinite":false,
|
||||||
|
"layers":[
|
||||||
|
{
|
||||||
|
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 2147483652, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||||
|
"height":30,
|
||||||
|
"id":1,
|
||||||
|
"name":"main",
|
||||||
|
"opacity":1,
|
||||||
|
"type":"tilelayer",
|
||||||
|
"visible":true,
|
||||||
|
"width":40,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"draworder":"topdown",
|
||||||
|
"id":2,
|
||||||
|
"name":"objects",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":14.8796,
|
||||||
|
"id":6,
|
||||||
|
"name":"spawn",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":14.8796,
|
||||||
|
"x":48.4346,
|
||||||
|
"y":240.503
|
||||||
|
}],
|
||||||
|
"opacity":1,
|
||||||
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"nextlayerid":3,
|
||||||
|
"nextobjectid":7,
|
||||||
|
"orientation":"orthogonal",
|
||||||
|
"renderorder":"right-down",
|
||||||
|
"tiledversion":"1.2.1",
|
||||||
|
"tileheight":16,
|
||||||
|
"tilesets":[
|
||||||
|
{
|
||||||
|
"columns":2,
|
||||||
|
"firstgid":1,
|
||||||
|
"image":"tileset.png",
|
||||||
|
"imageheight":32,
|
||||||
|
"imagewidth":32,
|
||||||
|
"margin":0,
|
||||||
|
"name":"tileset",
|
||||||
|
"spacing":0,
|
||||||
|
"tilecount":4,
|
||||||
|
"tileheight":16,
|
||||||
|
"tiles":[
|
||||||
|
{
|
||||||
|
"id":0,
|
||||||
|
"objectgroup":
|
||||||
|
{
|
||||||
|
"draworder":"index",
|
||||||
|
"name":"",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":16,
|
||||||
|
"id":1,
|
||||||
|
"name":"",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":16,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"opacity":1,
|
||||||
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":2,
|
||||||
|
"objectgroup":
|
||||||
|
{
|
||||||
|
"draworder":"index",
|
||||||
|
"name":"",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":3,
|
||||||
|
"id":1,
|
||||||
|
"name":"",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":16,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"opacity":1,
|
||||||
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"filewtf",
|
||||||
|
"type":"file",
|
||||||
|
"value":""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"floaty",
|
||||||
|
"type":"float",
|
||||||
|
"value":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"inty",
|
||||||
|
"type":"int",
|
||||||
|
"value":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"nez:isOneWayPlatform",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"poop",
|
||||||
|
"type":"color",
|
||||||
|
"value":""
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id":3,
|
||||||
|
"objectgroup":
|
||||||
|
{
|
||||||
|
"draworder":"index",
|
||||||
|
"name":"",
|
||||||
|
"objects":[
|
||||||
|
{
|
||||||
|
"height":0,
|
||||||
|
"id":1,
|
||||||
|
"name":"",
|
||||||
|
"polygon":[
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":0,
|
||||||
|
"y":16
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"x":16,
|
||||||
|
"y":16
|
||||||
|
}],
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":0,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
}],
|
||||||
|
"opacity":1,
|
||||||
|
"type":"objectgroup",
|
||||||
|
"visible":true,
|
||||||
|
"x":0,
|
||||||
|
"y":0
|
||||||
|
},
|
||||||
|
"properties":[
|
||||||
|
{
|
||||||
|
"name":"nez:isSlope",
|
||||||
|
"type":"bool",
|
||||||
|
"value":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"nez:slopeTopLeft",
|
||||||
|
"type":"int",
|
||||||
|
"value":0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"nez:slopeTopRight",
|
||||||
|
"type":"int",
|
||||||
|
"value":15
|
||||||
|
}]
|
||||||
|
}],
|
||||||
|
"tilewidth":16
|
||||||
|
}],
|
||||||
|
"tilewidth":16,
|
||||||
|
"type":"map",
|
||||||
|
"version":1.2,
|
||||||
|
"width":40
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -38,22 +38,6 @@ module samples {
|
|||||||
displayContainer.addChild(this._lineShape);
|
displayContainer.addChild(this._lineShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onAddedToEntity(): void {
|
|
||||||
KeyboardUtils.registerKey(KeyboardUtils.SPACE, this.spaceDown, this, KeyboardUtils.TYPE_KEY_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public onRemovedFromEntity(): void {
|
|
||||||
KeyboardUtils.unregisterKey(KeyboardUtils.SPACE, KeyboardUtils.TYPE_KEY_DOWN);
|
|
||||||
}
|
|
||||||
|
|
||||||
private spaceDown(){
|
|
||||||
let hit = Physics.linecast(this._lastPosition, this.transform.position);
|
|
||||||
if (hit.collider){
|
|
||||||
this._collisionPosition = hit.point;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public render(camera: es.Camera): any {
|
public render(camera: es.Camera): any {
|
||||||
this._pixelShape1.graphics.clear();
|
this._pixelShape1.graphics.clear();
|
||||||
this._pixelShape1.graphics.beginFill(0xffff00);
|
this._pixelShape1.graphics.beginFill(0xffff00);
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
module samples {
|
||||||
|
import Component = es.Component;
|
||||||
|
import Vector2 = es.Vector2;
|
||||||
|
|
||||||
|
export class CameraBounds extends Component {
|
||||||
|
public min: Vector2;
|
||||||
|
public max: Vector2;
|
||||||
|
|
||||||
|
constructor(min: Vector2 = Vector2.zero, max: Vector2 = Vector2.zero){
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
this.setUpdateOrder(Number.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onAddedToEntity(): void {
|
||||||
|
this.entity.updateOrder = Number.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(): void {
|
||||||
|
let cameraBounds = this.entity.scene.camera.bounds;
|
||||||
|
|
||||||
|
if (cameraBounds.top < this.min.y)
|
||||||
|
this.entity.scene.camera.position.add(new Vector2(0, this.min.y - cameraBounds.top));
|
||||||
|
|
||||||
|
if (cameraBounds.left < this.min.x)
|
||||||
|
this.entity.scene.camera.position.add(new Vector2(this.min.x - cameraBounds.left, 0));
|
||||||
|
|
||||||
|
if (cameraBounds.bottom > this.max.y)
|
||||||
|
this.entity.scene.camera.position.add(new Vector2(0, this.max.y - cameraBounds.bottom));
|
||||||
|
|
||||||
|
if (cameraBounds.right > this.max.x)
|
||||||
|
this.entity.scene.camera.position.add(new Vector2(this.max.x - cameraBounds.right, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
module samples {
|
||||||
|
import Component = es.Component;
|
||||||
|
import Vector2 = es.Vector2;
|
||||||
|
import ProjectileMover = es.ProjectileMover;
|
||||||
|
import Time = es.Time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移动一个投射器并在它击中任何东西时摧毁它
|
||||||
|
*/
|
||||||
|
export class FireballProjectileController extends Component {
|
||||||
|
public velocity: Vector2;
|
||||||
|
public _mover: ProjectileMover;
|
||||||
|
|
||||||
|
constructor(velocity: Vector2){
|
||||||
|
super();
|
||||||
|
this.velocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public onAddedToEntity(): void {
|
||||||
|
this._mover = this.entity.getComponent<ProjectileMover>(ProjectileMover);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(): void {
|
||||||
|
if (this._mover.move(Vector2.multiply(this.velocity, new Vector2(Time.deltaTime))))
|
||||||
|
this.entity.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,33 @@
|
|||||||
module samples {
|
module samples {
|
||||||
import SpriteAnimator = es.SpriteAnimator;
|
import SpriteAnimator = es.SpriteAnimator;
|
||||||
import Mover = es.Mover;
|
import Mover = es.Mover;
|
||||||
|
import VirtualButton = es.VirtualButton;
|
||||||
|
import VirtualIntegerAxis = es.VirtualIntegerAxis;
|
||||||
|
import KeyboardKey = es.KeyboardKey;
|
||||||
|
import KeyboardKeys = es.KeyboardKeys;
|
||||||
|
import OverlapBehavior = es.OverlapBehavior;
|
||||||
|
import Vector2 = es.Vector2;
|
||||||
|
import Time = es.Time;
|
||||||
|
import Keys = es.Keys;
|
||||||
|
import CollisionResult = es.CollisionResult;
|
||||||
|
import SubpixelVector2 = es.SubpixelVector2;
|
||||||
|
import ITriggerListener = es.ITriggerListener;
|
||||||
|
|
||||||
export class Ninja extends es.Component {
|
export class Ninja extends es.Component implements ITriggerListener{
|
||||||
public _animator: SpriteAnimator;
|
public _animator: SpriteAnimator;
|
||||||
|
|
||||||
|
public _subpixelV2: SubpixelVector2 = new SubpixelVector2();
|
||||||
public _mover: Mover;
|
public _mover: Mover;
|
||||||
|
public _moveSpeed = 100;
|
||||||
|
public _projectileVelocity: Vector2 = new Vector2(175);
|
||||||
|
|
||||||
|
public _fireInput: VirtualButton;
|
||||||
|
public _xAxisInput: VirtualIntegerAxis;
|
||||||
|
public _yAxisInput: VirtualIntegerAxis;
|
||||||
|
|
||||||
public onAddedToEntity(): void {
|
public onAddedToEntity(): void {
|
||||||
let characterPng = RandomUtils.randint(1, 6);
|
let characterPng = RandomUtils.randint(1, 6);
|
||||||
this.entity.scene.content.loadRes(`${characterPng}_png`).then(texture => {
|
let texture = RES.getRes(`${characterPng}_png`);
|
||||||
let sprites = es.Sprite.spritesFromAtlas(texture, 16, 16);
|
let sprites = es.Sprite.spritesFromAtlas(texture, 16, 16);
|
||||||
|
|
||||||
this._mover = this.entity.addComponent(new Mover());
|
this._mover = this.entity.addComponent(new Mover());
|
||||||
@@ -43,8 +61,85 @@ module samples {
|
|||||||
sprites[13]
|
sprites[13]
|
||||||
], 4));
|
], 4));
|
||||||
|
|
||||||
this._animator.play("walkDown");
|
this.setupInput();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
public onRemovedFromEntity(): void {
|
||||||
|
this._fireInput.deregister();
|
||||||
|
}
|
||||||
|
|
||||||
|
public setupInput(){
|
||||||
|
// 设置输入射击一个火球。我们允许在键盘z上使用
|
||||||
|
this._fireInput = new VirtualButton();
|
||||||
|
this._fireInput.nodes.push(new KeyboardKey(Keys.z));
|
||||||
|
|
||||||
|
this._xAxisInput = new VirtualIntegerAxis();
|
||||||
|
this._xAxisInput.nodes.push(new KeyboardKeys(OverlapBehavior.takeNewer, Keys.left, Keys.right));
|
||||||
|
|
||||||
|
this._yAxisInput = new VirtualIntegerAxis();
|
||||||
|
this._yAxisInput.nodes.push(new KeyboardKeys(OverlapBehavior.takeNewer, Keys.up, Keys.down));
|
||||||
|
}
|
||||||
|
|
||||||
|
public update(): void {
|
||||||
|
let moveDir = new Vector2(this._xAxisInput.value, this._yAxisInput.value);
|
||||||
|
let animation = "walkDown";
|
||||||
|
|
||||||
|
if (moveDir.x < 0)
|
||||||
|
animation = "walkLeft";
|
||||||
|
else if(moveDir.x > 0)
|
||||||
|
animation = "walkRight";
|
||||||
|
|
||||||
|
if (moveDir.y < 0)
|
||||||
|
animation = "walkUp";
|
||||||
|
else if(moveDir.y > 0)
|
||||||
|
animation = "walkDown";
|
||||||
|
|
||||||
|
if (!moveDir.equals(Vector2.zero)){
|
||||||
|
if (!this._animator.isAnimationActive(animation))
|
||||||
|
this._animator.play(animation);
|
||||||
|
else
|
||||||
|
this._animator.unPause();
|
||||||
|
|
||||||
|
let movement = Vector2.multiply(moveDir, new Vector2(this._moveSpeed * Time.deltaTime));
|
||||||
|
let res: CollisionResult = new CollisionResult();
|
||||||
|
this._mover.calculateMovement(movement, res);
|
||||||
|
this._subpixelV2.update(movement);
|
||||||
|
this._mover.applyMovement(movement);
|
||||||
|
}else{
|
||||||
|
this._animator.pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._fireInput.isPressed){
|
||||||
|
let dir = Vector2.zero;
|
||||||
|
switch (this._animator.currentAnimationName) {
|
||||||
|
case "walkUp":
|
||||||
|
dir.y = -1;
|
||||||
|
break;
|
||||||
|
case "walkDown":
|
||||||
|
dir.y = 1;
|
||||||
|
break;
|
||||||
|
case "walkRight":
|
||||||
|
dir.x = 1;
|
||||||
|
break;
|
||||||
|
case "walkLeft":
|
||||||
|
dir.x = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dir = new Vector2(1, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let ninjaScene = this.entity.scene as NinjaAdventureScene;
|
||||||
|
ninjaScene.createProjectiles(this.entity.transform.position, Vector2.multiply(this._projectileVelocity, dir));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public onTriggerEnter(other: es.Collider, local: es.Collider): any {
|
||||||
|
console.log(`triggerEnter: ${other.entity.name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public onTriggerExit(other: es.Collider, local: es.Collider): any {
|
||||||
|
console.log(`triggerExit: ${other.entity.name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,38 @@ module samples {
|
|||||||
import SpriteRenderer = es.SpriteRenderer;
|
import SpriteRenderer = es.SpriteRenderer;
|
||||||
import ProjectileHitDetector = es.ProjectileHitDetector;
|
import ProjectileHitDetector = es.ProjectileHitDetector;
|
||||||
import FollowCamera = es.FollowCamera;
|
import FollowCamera = es.FollowCamera;
|
||||||
|
import TiledMapLoader = es.TiledMapLoader;
|
||||||
|
import TiledMapRenderer = es.TiledMapRenderer;
|
||||||
|
import Vector2 = es.Vector2;
|
||||||
|
import ProjectileMover = es.ProjectileMover;
|
||||||
|
import Sprite = es.Sprite;
|
||||||
|
import SpriteAnimator = es.SpriteAnimator;
|
||||||
|
import SpriteAnimation = es.SpriteAnimation;
|
||||||
|
|
||||||
export class NinjaAdventureScene extends SampleScene {
|
export class NinjaAdventureScene extends SampleScene {
|
||||||
public async onStart() {
|
public async onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
|
let tiledEntity = this.createEntity("tiled-map-entity");
|
||||||
|
TiledMapLoader.loadTmxMap(new es.TmxMap(), "tilemap_json").then(map => {
|
||||||
|
let tiledMapRenderer = tiledEntity.addComponent(new TiledMapRenderer(map, "collision"));
|
||||||
|
tiledMapRenderer.setLayersToRender("tiles", "terrain", "details");
|
||||||
|
|
||||||
|
tiledMapRenderer.renderLayer = 10;
|
||||||
|
|
||||||
|
let tiledMapDetailsComp = tiledEntity.addComponent(new TiledMapRenderer(map));
|
||||||
|
tiledMapRenderer.setLayerToRender("above-details");
|
||||||
|
tiledMapRenderer.renderLayer = -1;
|
||||||
|
|
||||||
|
let topLeft = new Vector2(map.tileWidth, map.tileWidth);
|
||||||
|
let bottomRight = new Vector2(map.tileWidth * (map.width - 1),
|
||||||
|
map.tileWidth * (map.height - 1));
|
||||||
|
tiledEntity.addComponent(new CameraBounds(topLeft, bottomRight));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
let playerEntity = this.createEntity("player");
|
let playerEntity = this.createEntity("player");
|
||||||
playerEntity.position = new es.Vector2(256, 224);
|
playerEntity.position = new es.Vector2(256 / 2, 224 / 2);
|
||||||
playerEntity.addComponent(new Ninja());
|
playerEntity.addComponent(new Ninja());
|
||||||
let collider = playerEntity.addComponent(new CircleCollider());
|
let collider = playerEntity.addComponent(new CircleCollider());
|
||||||
|
|
||||||
@@ -21,20 +46,39 @@ module samples {
|
|||||||
|
|
||||||
this.camera.entity.addComponent(new FollowCamera(playerEntity));
|
this.camera.entity.addComponent(new FollowCamera(playerEntity));
|
||||||
|
|
||||||
this.content.loadRes("moon_png").then(moonTexture => {
|
let moonTexture = RES.getRes("moon_png");
|
||||||
let moonEntity = this.createEntity("moon");
|
let moonEntity = this.createEntity("moon");
|
||||||
moonEntity.position = new es.Vector2(412, 460);
|
moonEntity.position = new es.Vector2(412, 460);
|
||||||
moonEntity.addComponent(new SpriteRenderer(moonTexture));
|
moonEntity.addComponent(new SpriteRenderer(moonTexture));
|
||||||
moonEntity.addComponent(new ProjectileHitDetector());
|
moonEntity.addComponent(new ProjectileHitDetector());
|
||||||
moonEntity.addComponent(new CircleCollider());
|
moonEntity.addComponent(new CircleCollider());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(){
|
/**
|
||||||
super.update();
|
* 创建抛射物并使其运动
|
||||||
|
* @param position
|
||||||
|
* @param velocity
|
||||||
|
*/
|
||||||
|
public createProjectiles(position: Vector2, velocity: Vector2) {
|
||||||
|
// 创建一个实体来存放投射程序及其逻辑
|
||||||
|
let entity = this.createEntity("projectile");
|
||||||
|
entity.position = position;
|
||||||
|
entity.addComponent(new ProjectileMover());
|
||||||
|
entity.addComponent(new FireballProjectileController(velocity));
|
||||||
|
|
||||||
this.findEntity("player").position.x -= es.Time.deltaTime * 10;
|
let collider = entity.addComponent(new CircleCollider());
|
||||||
this.findEntity("player").position.y -= es.Time.deltaTime * 10;
|
Flags.setFlagExclusive(collider.collidesWithLayers, 0);
|
||||||
|
Flags.setFlagExclusive(collider.physicsLayer, 1);
|
||||||
|
|
||||||
|
let texture = RES.getRes("plume_png");
|
||||||
|
let sprites = Sprite.spritesFromAtlas(texture, 16, 16);
|
||||||
|
let animator = entity.addComponent(new SpriteAnimator());
|
||||||
|
animator.renderLayer = 1;
|
||||||
|
|
||||||
|
animator.addAnimation("default", new SpriteAnimation(sprites));
|
||||||
|
animator.play("default");
|
||||||
|
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+260
-139
@@ -285,7 +285,6 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
setEnabled(isEnabled: boolean): this;
|
setEnabled(isEnabled: boolean): this;
|
||||||
setUpdateOrder(updateOrder: number): this;
|
setUpdateOrder(updateOrder: number): this;
|
||||||
clone(): Component;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -334,7 +333,6 @@ declare module es {
|
|||||||
destroy(): void;
|
destroy(): void;
|
||||||
detachFromScene(): void;
|
detachFromScene(): void;
|
||||||
attachToScene(newScene: Scene): void;
|
attachToScene(newScene: Scene): void;
|
||||||
clone(position?: Vector2): Entity;
|
|
||||||
onAddedToScene(): void;
|
onAddedToScene(): void;
|
||||||
onRemovedFromScene(): void;
|
onRemovedFromScene(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
@@ -349,7 +347,6 @@ declare module es {
|
|||||||
removeAllComponents(): void;
|
removeAllComponents(): void;
|
||||||
compareTo(other: Entity): number;
|
compareTo(other: Entity): number;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
protected copyFrom(entity: Entity): void;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -691,7 +688,7 @@ declare module es {
|
|||||||
class SpriteAnimation {
|
class SpriteAnimation {
|
||||||
readonly sprites: Sprite[];
|
readonly sprites: Sprite[];
|
||||||
readonly frameRate: number;
|
readonly frameRate: number;
|
||||||
constructor(sprites: Sprite[], frameRate: number);
|
constructor(sprites: Sprite[], frameRate?: number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -759,7 +756,7 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
class TiledMapRenderer extends RenderableComponent {
|
class TiledMapRenderer extends RenderableComponent {
|
||||||
tiledMap: TmxMap;
|
tiledMap: TmxMap;
|
||||||
physicsLayer: number;
|
physicsLayer: Ref<number>;
|
||||||
layerIndicesToRender: number[];
|
layerIndicesToRender: number[];
|
||||||
private toContainer;
|
private toContainer;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
@@ -808,11 +805,10 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class Collider extends Component {
|
abstract class Collider extends Component {
|
||||||
debug: any;
|
|
||||||
shape: Shape;
|
shape: Shape;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
physicsLayer: number;
|
physicsLayer: Ref<number>;
|
||||||
collidesWithLayers: number;
|
collidesWithLayers: Ref<number>;
|
||||||
shouldColliderScaleAndRotateWithTransform: boolean;
|
shouldColliderScaleAndRotateWithTransform: boolean;
|
||||||
registeredPhysicsBounds: Rectangle;
|
registeredPhysicsBounds: Rectangle;
|
||||||
_localOffsetLength: number;
|
_localOffsetLength: number;
|
||||||
@@ -837,7 +833,6 @@ declare module es {
|
|||||||
unregisterColliderWithPhysicsSystem(): void;
|
unregisterColliderWithPhysicsSystem(): void;
|
||||||
overlaps(other: Collider): boolean;
|
overlaps(other: Collider): boolean;
|
||||||
collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
|
collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean;
|
||||||
clone(): Component;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -846,10 +841,9 @@ declare module es {
|
|||||||
polygonShape: egret.Shape;
|
polygonShape: egret.Shape;
|
||||||
pixelShape1: egret.Shape;
|
pixelShape1: egret.Shape;
|
||||||
pixelShape2: egret.Shape;
|
pixelShape2: egret.Shape;
|
||||||
constructor();
|
constructor(x?: number, y?: number, width?: number, height?: number);
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
createBoxRect(x: number, y: number, width: number, height: number): BoxCollider;
|
|
||||||
setSize(width: number, height: number): this;
|
setSize(width: number, height: number): this;
|
||||||
setWidth(width: number): BoxCollider;
|
setWidth(width: number): BoxCollider;
|
||||||
setHeight(height: number): void;
|
setHeight(height: number): void;
|
||||||
@@ -1303,10 +1297,10 @@ declare module es {
|
|||||||
class Flags {
|
class Flags {
|
||||||
static isFlagSet(self: number, flag: number): boolean;
|
static isFlagSet(self: number, flag: number): boolean;
|
||||||
static isUnshiftedFlagSet(self: number, flag: number): boolean;
|
static isUnshiftedFlagSet(self: number, flag: number): boolean;
|
||||||
static setFlagExclusive(self: number, flag: number): number;
|
static setFlagExclusive(self: Ref<number>, flag: number): void;
|
||||||
static setFlag(self: number, flag: number): number;
|
static setFlag(self: Ref<number>, flag: number): void;
|
||||||
static unsetFlag(self: number, flag: number): number;
|
static unsetFlag(self: Ref<number>, flag: number): void;
|
||||||
static invertFlags(self: number): number;
|
static invertFlags(self: Ref<number>): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1422,12 +1416,12 @@ declare module es {
|
|||||||
static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
|
static isLineToLine(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): boolean;
|
||||||
static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
|
static lineToLineIntersection(a1: Vector2, a2: Vector2, b1: Vector2, b2: Vector2): Vector2;
|
||||||
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
|
||||||
static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
|
static circleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean;
|
||||||
static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
|
static circleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean;
|
||||||
static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
|
static circleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean;
|
||||||
static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
|
static rectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean;
|
||||||
static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
|
static rectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2): boolean;
|
||||||
static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
|
static rectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2): boolean;
|
||||||
static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
|
static getSector(rX: number, rY: number, rW: number, rH: number, point: Vector2): PointSectors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1486,7 +1480,6 @@ declare module es {
|
|||||||
abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
|
abstract collidesWithLine(start: Vector2, end: Vector2, hit: RaycastHit): boolean;
|
||||||
abstract containsPoint(point: Vector2): any;
|
abstract containsPoint(point: Vector2): any;
|
||||||
abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
||||||
clone(): Shape;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
@@ -1508,7 +1501,7 @@ declare module es {
|
|||||||
static findPolygonCenter(points: Vector2[]): Vector2;
|
static findPolygonCenter(points: Vector2[]): Vector2;
|
||||||
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
||||||
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref<number>, edgeNormal: Vector2): Vector2;
|
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Ref<number>, edgeNormal: Vector2): Vector2;
|
||||||
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]): void;
|
||||||
recalculateBounds(collider: Collider): void;
|
recalculateBounds(collider: Collider): void;
|
||||||
overlaps(other: Shape): any;
|
overlaps(other: Shape): any;
|
||||||
collidesWithShape(other: Shape, result: CollisionResult): boolean;
|
collidesWithShape(other: Shape, result: CollisionResult): boolean;
|
||||||
@@ -2051,122 +2044,6 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class TouchState {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
touchPoint: number;
|
|
||||||
touchDown: boolean;
|
|
||||||
readonly position: Vector2;
|
|
||||||
reset(): void;
|
|
||||||
}
|
|
||||||
class Input {
|
|
||||||
private static _init;
|
|
||||||
private static _previousTouchState;
|
|
||||||
private static _resolutionOffset;
|
|
||||||
private static _touchIndex;
|
|
||||||
private static _gameTouchs;
|
|
||||||
static readonly gameTouchs: TouchState[];
|
|
||||||
private static _resolutionScale;
|
|
||||||
static readonly resolutionScale: Vector2;
|
|
||||||
private static _totalTouchCount;
|
|
||||||
static readonly totalTouchCount: number;
|
|
||||||
static readonly touchPosition: Vector2;
|
|
||||||
static maxSupportedTouch: number;
|
|
||||||
static readonly touchPositionDelta: Vector2;
|
|
||||||
static initialize(): void;
|
|
||||||
static scaledPosition(position: Vector2): Vector2;
|
|
||||||
private static initTouchCache;
|
|
||||||
private static touchBegin;
|
|
||||||
private static touchMove;
|
|
||||||
private static touchEnd;
|
|
||||||
private static setpreviousTouchState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare class KeyboardUtils {
|
|
||||||
static TYPE_KEY_DOWN: number;
|
|
||||||
static TYPE_KEY_UP: number;
|
|
||||||
static A: string;
|
|
||||||
static B: string;
|
|
||||||
static C: string;
|
|
||||||
static D: string;
|
|
||||||
static E: string;
|
|
||||||
static F: string;
|
|
||||||
static G: string;
|
|
||||||
static H: string;
|
|
||||||
static I: string;
|
|
||||||
static J: string;
|
|
||||||
static K: string;
|
|
||||||
static L: string;
|
|
||||||
static M: string;
|
|
||||||
static N: string;
|
|
||||||
static O: string;
|
|
||||||
static P: string;
|
|
||||||
static Q: string;
|
|
||||||
static R: string;
|
|
||||||
static S: string;
|
|
||||||
static T: string;
|
|
||||||
static U: string;
|
|
||||||
static V: string;
|
|
||||||
static W: string;
|
|
||||||
static X: string;
|
|
||||||
static Y: string;
|
|
||||||
static Z: string;
|
|
||||||
static ESC: string;
|
|
||||||
static F1: string;
|
|
||||||
static F2: string;
|
|
||||||
static F3: string;
|
|
||||||
static F4: string;
|
|
||||||
static F5: string;
|
|
||||||
static F6: string;
|
|
||||||
static F7: string;
|
|
||||||
static F8: string;
|
|
||||||
static F9: string;
|
|
||||||
static F10: string;
|
|
||||||
static F11: string;
|
|
||||||
static F12: string;
|
|
||||||
static NUM_1: string;
|
|
||||||
static NUM_2: string;
|
|
||||||
static NUM_3: string;
|
|
||||||
static NUM_4: string;
|
|
||||||
static NUM_5: string;
|
|
||||||
static NUM_6: string;
|
|
||||||
static NUM_7: string;
|
|
||||||
static NUM_8: string;
|
|
||||||
static NUM_9: string;
|
|
||||||
static NUM_0: string;
|
|
||||||
static TAB: string;
|
|
||||||
static CTRL: string;
|
|
||||||
static ALT: string;
|
|
||||||
static SHIFT: string;
|
|
||||||
static CAPS_LOCK: string;
|
|
||||||
static ENTER: string;
|
|
||||||
static SPACE: string;
|
|
||||||
static BACK_SPACE: string;
|
|
||||||
static INSERT: string;
|
|
||||||
static DELETE: string;
|
|
||||||
static HOME: string;
|
|
||||||
static END: string;
|
|
||||||
static PAGE_UP: string;
|
|
||||||
static PAGE_DOWN: string;
|
|
||||||
static LEFT: string;
|
|
||||||
static RIGHT: string;
|
|
||||||
static UP: string;
|
|
||||||
static DOWN: string;
|
|
||||||
static PAUSE_BREAK: string;
|
|
||||||
static NUM_LOCK: string;
|
|
||||||
static SCROLL_LOCK: string;
|
|
||||||
static WINDOWS: string;
|
|
||||||
private static keyDownDict;
|
|
||||||
private static keyUpDict;
|
|
||||||
static init(): void;
|
|
||||||
static registerKey(key: string, fun: Function, thisObj: any, type?: number, ...args: any[]): void;
|
|
||||||
static unregisterKey(key: string, type?: number): void;
|
|
||||||
static destroy(): void;
|
|
||||||
private static onKeyDonwHander;
|
|
||||||
private static onKeyUpHander;
|
|
||||||
private static keyCodeToString;
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
class ListPool {
|
class ListPool {
|
||||||
private static readonly _objectQueue;
|
private static readonly _objectQueue;
|
||||||
@@ -2386,6 +2263,250 @@ declare module es {
|
|||||||
initialized: boolean;
|
initialized: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class TouchState {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
touchPoint: number;
|
||||||
|
touchDown: boolean;
|
||||||
|
readonly position: Vector2;
|
||||||
|
reset(): void;
|
||||||
|
}
|
||||||
|
class Input {
|
||||||
|
private static _init;
|
||||||
|
private static _previousTouchState;
|
||||||
|
private static _resolutionOffset;
|
||||||
|
private static _touchIndex;
|
||||||
|
private static _gameTouchs;
|
||||||
|
static readonly gameTouchs: TouchState[];
|
||||||
|
private static _resolutionScale;
|
||||||
|
static readonly resolutionScale: Vector2;
|
||||||
|
private static _totalTouchCount;
|
||||||
|
static readonly totalTouchCount: number;
|
||||||
|
static readonly touchPosition: Vector2;
|
||||||
|
static _virtualInputs: VirtualInput[];
|
||||||
|
static maxSupportedTouch: number;
|
||||||
|
static readonly touchPositionDelta: Vector2;
|
||||||
|
static initialize(): void;
|
||||||
|
static update(): void;
|
||||||
|
static scaledPosition(position: Vector2): Vector2;
|
||||||
|
static isKeyPressed(key: Keys): boolean;
|
||||||
|
static isKeyPressedBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
static isKeyDown(key: Keys): boolean;
|
||||||
|
static isKeyDownBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
static isKeyReleased(key: Keys): boolean;
|
||||||
|
static isKeyReleasedBoth(keyA: Keys, keyB: Keys): boolean;
|
||||||
|
private static initTouchCache;
|
||||||
|
private static touchBegin;
|
||||||
|
private static touchMove;
|
||||||
|
private static touchEnd;
|
||||||
|
private static setpreviousTouchState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
import Keys = es.Keys;
|
||||||
|
declare class KeyboardUtils {
|
||||||
|
static currentKeys: Keys[];
|
||||||
|
static previousKeys: Keys[];
|
||||||
|
private static keyStatusKeys;
|
||||||
|
static init(): void;
|
||||||
|
static update(): void;
|
||||||
|
static destroy(): void;
|
||||||
|
private static onKeyDownHandler;
|
||||||
|
private static onKeyUpHandler;
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
enum Keys {
|
||||||
|
none = 0,
|
||||||
|
back = 8,
|
||||||
|
tab = 9,
|
||||||
|
enter = 13,
|
||||||
|
capsLock = 20,
|
||||||
|
escape = 27,
|
||||||
|
space = 32,
|
||||||
|
pageUp = 33,
|
||||||
|
pageDown = 34,
|
||||||
|
end = 35,
|
||||||
|
home = 36,
|
||||||
|
left = 37,
|
||||||
|
up = 38,
|
||||||
|
right = 39,
|
||||||
|
down = 40,
|
||||||
|
select = 41,
|
||||||
|
print = 42,
|
||||||
|
execute = 43,
|
||||||
|
printScreen = 44,
|
||||||
|
insert = 45,
|
||||||
|
delete = 46,
|
||||||
|
help = 47,
|
||||||
|
d0 = 48,
|
||||||
|
d1 = 49,
|
||||||
|
d2 = 50,
|
||||||
|
d3 = 51,
|
||||||
|
d4 = 52,
|
||||||
|
d5 = 53,
|
||||||
|
d6 = 54,
|
||||||
|
d7 = 55,
|
||||||
|
d8 = 56,
|
||||||
|
d9 = 57,
|
||||||
|
a = 65,
|
||||||
|
b = 66,
|
||||||
|
c = 67,
|
||||||
|
d = 68,
|
||||||
|
e = 69,
|
||||||
|
f = 70,
|
||||||
|
g = 71,
|
||||||
|
h = 72,
|
||||||
|
i = 73,
|
||||||
|
j = 74,
|
||||||
|
k = 75,
|
||||||
|
l = 76,
|
||||||
|
m = 77,
|
||||||
|
n = 78,
|
||||||
|
o = 79,
|
||||||
|
p = 80,
|
||||||
|
q = 81,
|
||||||
|
r = 82,
|
||||||
|
s = 83,
|
||||||
|
t = 84,
|
||||||
|
u = 85,
|
||||||
|
v = 86,
|
||||||
|
w = 87,
|
||||||
|
x = 88,
|
||||||
|
y = 89,
|
||||||
|
z = 90,
|
||||||
|
leftWindows = 91,
|
||||||
|
rightWindows = 92,
|
||||||
|
apps = 93,
|
||||||
|
sleep = 95,
|
||||||
|
numPad0 = 96,
|
||||||
|
numPad1 = 97,
|
||||||
|
numPad2 = 98,
|
||||||
|
numPad3 = 99,
|
||||||
|
numPad4 = 100,
|
||||||
|
numPad5 = 101,
|
||||||
|
numPad6 = 102,
|
||||||
|
numPad7 = 103,
|
||||||
|
numPad8 = 104,
|
||||||
|
numPad9 = 105,
|
||||||
|
multiply = 106,
|
||||||
|
add = 107,
|
||||||
|
seperator = 108,
|
||||||
|
subtract = 109,
|
||||||
|
decimal = 110,
|
||||||
|
divide = 111,
|
||||||
|
f1 = 112,
|
||||||
|
f2 = 113,
|
||||||
|
f3 = 114,
|
||||||
|
f4 = 115,
|
||||||
|
f5 = 116,
|
||||||
|
f6 = 117,
|
||||||
|
f7 = 118,
|
||||||
|
f8 = 119,
|
||||||
|
f9 = 120,
|
||||||
|
f10 = 121,
|
||||||
|
f11 = 122,
|
||||||
|
f12 = 123,
|
||||||
|
f13 = 124,
|
||||||
|
f14 = 125,
|
||||||
|
f15 = 126,
|
||||||
|
f16 = 127,
|
||||||
|
f17 = 128,
|
||||||
|
f18 = 129,
|
||||||
|
f19 = 130,
|
||||||
|
f20 = 131,
|
||||||
|
f21 = 132,
|
||||||
|
f22 = 133,
|
||||||
|
f23 = 134,
|
||||||
|
f24 = 135,
|
||||||
|
numLock = 144,
|
||||||
|
scroll = 145,
|
||||||
|
leftShift = 160,
|
||||||
|
rightShift = 161,
|
||||||
|
leftControl = 162,
|
||||||
|
rightControl = 163,
|
||||||
|
leftAlt = 164,
|
||||||
|
rightAlt = 165,
|
||||||
|
browserBack = 166,
|
||||||
|
browserForward = 167
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
enum OverlapBehavior {
|
||||||
|
cancelOut = 0,
|
||||||
|
takeOlder = 1,
|
||||||
|
takeNewer = 2
|
||||||
|
}
|
||||||
|
abstract class VirtualInput {
|
||||||
|
protected constructor();
|
||||||
|
deregister(): void;
|
||||||
|
abstract update(): any;
|
||||||
|
}
|
||||||
|
abstract class VirtualInputNode {
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualIntegerAxis extends VirtualInput {
|
||||||
|
nodes: VirtualAxisNode[];
|
||||||
|
readonly value: number;
|
||||||
|
constructor(...nodes: VirtualAxisNode[]);
|
||||||
|
update(): void;
|
||||||
|
addKeyboardKeys(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys): this;
|
||||||
|
}
|
||||||
|
abstract class VirtualAxisNode extends VirtualInputNode {
|
||||||
|
abstract value: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualAxis extends VirtualInput {
|
||||||
|
nodes: VirtualAxisNode[];
|
||||||
|
readonly value: number;
|
||||||
|
constructor(...nodes: VirtualAxisNode[]);
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
class KeyboardKeys extends VirtualAxisNode {
|
||||||
|
overlapBehavior: OverlapBehavior;
|
||||||
|
positive: Keys;
|
||||||
|
negative: Keys;
|
||||||
|
_value: number;
|
||||||
|
_turned: boolean;
|
||||||
|
constructor(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys);
|
||||||
|
update(): void;
|
||||||
|
readonly value: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class VirtualButton extends VirtualInput {
|
||||||
|
nodes: Node[];
|
||||||
|
bufferTime: number;
|
||||||
|
firstRepeatTime: number;
|
||||||
|
mutiRepeatTime: number;
|
||||||
|
isRepeating: boolean;
|
||||||
|
_bufferCounter: number;
|
||||||
|
_repeatCounter: number;
|
||||||
|
_willRepeat: boolean;
|
||||||
|
constructor(bufferTime?: number, ...nodes: Node[]);
|
||||||
|
setRepeat(firstRepeatTime: number, mutiRepeatTime?: number): void;
|
||||||
|
update(): void;
|
||||||
|
readonly isDown: boolean;
|
||||||
|
readonly isPressed: boolean;
|
||||||
|
readonly isReleased: boolean;
|
||||||
|
consumeBuffer(): void;
|
||||||
|
addKeyboardKey(key: Keys): VirtualButton;
|
||||||
|
}
|
||||||
|
abstract class Node extends VirtualInputNode {
|
||||||
|
abstract isDown: boolean;
|
||||||
|
abstract isPressed: boolean;
|
||||||
|
abstract isReleased: boolean;
|
||||||
|
}
|
||||||
|
class KeyboardKey extends Node {
|
||||||
|
key: Keys;
|
||||||
|
constructor(key: Keys);
|
||||||
|
readonly isDown: boolean;
|
||||||
|
readonly isPressed: boolean;
|
||||||
|
readonly isReleased: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class AssetPacker {
|
class AssetPacker {
|
||||||
protected itemsToRaster: TextureToPack[];
|
protected itemsToRaster: TextureToPack[];
|
||||||
|
|||||||
+734
-449
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -127,15 +127,5 @@ module es {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建此组件的克隆
|
|
||||||
*/
|
|
||||||
public clone(): Component {
|
|
||||||
let component = ObjectUtils.clone<Component>(this);
|
|
||||||
component.entity = null;
|
|
||||||
|
|
||||||
return component;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,24 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor(x?: number, y?: number, width?: number, height?: number) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
if (x == undefined && y == undefined){
|
||||||
|
if (width == undefined && height == undefined){
|
||||||
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
||||||
this.shape = new Box(1, 1);
|
this.shape = new Box(1, 1);
|
||||||
this._colliderRequiresAutoSizing = true;
|
this._colliderRequiresAutoSizing = true;
|
||||||
|
}else if (width != undefined && height != undefined){
|
||||||
|
x = -width / 2;
|
||||||
|
y = -height / 2;
|
||||||
|
this._localOffset = new Vector2(x + width / 2, y + height / 2);
|
||||||
|
this.shape = new Box(width, height);
|
||||||
|
}
|
||||||
|
}else if (x != undefined && y != undefined && width != undefined && height != undefined){
|
||||||
|
this._localOffset = new Vector2(x + width / 2, y + height / 2);
|
||||||
|
this.shape = new Box(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get width() {
|
public get width() {
|
||||||
@@ -32,20 +44,6 @@ module es {
|
|||||||
this.setHeight(value);
|
this.setHeight(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建一个BoxCollider并使用x/y组件作为localOffset
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param width
|
|
||||||
* @param height
|
|
||||||
*/
|
|
||||||
public createBoxRect(x: number, y: number, width: number, height: number): BoxCollider{
|
|
||||||
this._localOffset = new Vector2(x + width / 2, y + width / 2);
|
|
||||||
this.shape = new Box(width, height);
|
|
||||||
this._colliderRequiresAutoSizing = false;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置BoxCollider的大小
|
* 设置BoxCollider的大小
|
||||||
* @param width
|
* @param width
|
||||||
@@ -110,11 +108,11 @@ module es {
|
|||||||
if (!this.pixelShape2.parent)
|
if (!this.pixelShape2.parent)
|
||||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||||
|
|
||||||
// this.hollowShape.graphics.clear();
|
this.hollowShape.graphics.clear();
|
||||||
// this.hollowShape.graphics.beginFill(Colors.colliderBounds, 0);
|
this.hollowShape.graphics.beginFill(Colors.colliderBounds, 0);
|
||||||
// this.hollowShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
|
this.hollowShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
|
||||||
// this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||||
// this.hollowShape.graphics.endFill();
|
this.hollowShape.graphics.endFill();
|
||||||
|
|
||||||
this.polygonShape.graphics.clear();
|
this.polygonShape.graphics.clear();
|
||||||
if (poly.points.length >= 2){
|
if (poly.points.length >= 2){
|
||||||
|
|||||||
@@ -13,11 +13,14 @@ module es {
|
|||||||
constructor(radius?: number) {
|
constructor(radius?: number) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
if (radius)
|
if (radius == undefined){
|
||||||
this._colliderRequiresAutoSizing = true;
|
|
||||||
// 我们在这里插入一个1px的圆圈作为占位符
|
// 我们在这里插入一个1px的圆圈作为占位符
|
||||||
// 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧
|
// 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧
|
||||||
this.shape = new Circle(radius ? radius : 1);
|
this.shape = new Circle(1);
|
||||||
|
this._colliderRequiresAutoSizing = true;
|
||||||
|
}else{
|
||||||
|
this.shape = new Circle(radius);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get radius(): number {
|
public get radius(): number {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
module es {
|
module es {
|
||||||
export abstract class Collider extends Component {
|
export abstract class Collider extends Component {
|
||||||
public debug
|
|
||||||
/**
|
/**
|
||||||
* 对撞机的基本形状
|
* 对撞机的基本形状
|
||||||
*/
|
*/
|
||||||
@@ -12,12 +11,12 @@ module es {
|
|||||||
/**
|
/**
|
||||||
* 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法
|
* 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法
|
||||||
*/
|
*/
|
||||||
public physicsLayer = 1 << 0;
|
public physicsLayer = new Ref(1 << 0);
|
||||||
/**
|
/**
|
||||||
* 碰撞器在使用移动器移动时应该碰撞的层
|
* 碰撞器在使用移动器移动时应该碰撞的层
|
||||||
* 默认为所有层
|
* 默认为所有层
|
||||||
*/
|
*/
|
||||||
public collidesWithLayers = Physics.allLayers;
|
public collidesWithLayers: Ref<number> = new Ref(Physics.allLayers);
|
||||||
/**
|
/**
|
||||||
* 如果为true,碰撞器将根据附加的变换缩放和旋转
|
* 如果为true,碰撞器将根据附加的变换缩放和旋转
|
||||||
*/
|
*/
|
||||||
@@ -124,8 +123,8 @@ module es {
|
|||||||
let renderableBounds = renderable.bounds;
|
let renderableBounds = renderable.bounds;
|
||||||
|
|
||||||
// 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染
|
// 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染
|
||||||
let width = renderableBounds.width / this.entity.scale.x;
|
let width = renderableBounds.width / this.entity.transform.scale.x;
|
||||||
let height = renderableBounds.height / this.entity.scale.y;
|
let height = renderableBounds.height / this.entity.transform.scale.y;
|
||||||
// 圆碰撞器需要特别注意原点
|
// 圆碰撞器需要特别注意原点
|
||||||
if (this instanceof CircleCollider) {
|
if (this instanceof CircleCollider) {
|
||||||
this.radius = Math.max(width, height) * 0.5;
|
this.radius = Math.max(width, height) * 0.5;
|
||||||
@@ -214,7 +213,7 @@ module es {
|
|||||||
public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean {
|
public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean {
|
||||||
// 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
|
// 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
|
||||||
let oldPosition = this.entity.position;
|
let oldPosition = this.entity.position;
|
||||||
this.entity.position = this.entity.position.add(motion);
|
this.entity.position.add(motion);
|
||||||
|
|
||||||
let didCollide = this.shape.collidesWithShape(collider.shape, result);
|
let didCollide = this.shape.collidesWithShape(collider.shape, result);
|
||||||
if (didCollide)
|
if (didCollide)
|
||||||
@@ -225,15 +224,5 @@ module es {
|
|||||||
|
|
||||||
return didCollide;
|
return didCollide;
|
||||||
}
|
}
|
||||||
|
|
||||||
public clone(): Component {
|
|
||||||
let collider = ObjectUtils.clone<Collider>(this);
|
|
||||||
collider.entity = null;
|
|
||||||
|
|
||||||
if (this.shape)
|
|
||||||
collider.shape = this.shape.clone();
|
|
||||||
|
|
||||||
return collider;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ module es {
|
|||||||
let bounds = collider.bounds;
|
let bounds = collider.bounds;
|
||||||
bounds.x += motion.x;
|
bounds.x += motion.x;
|
||||||
bounds.y += motion.y;
|
bounds.y += motion.y;
|
||||||
let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
|
let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers.value);
|
||||||
|
|
||||||
for (let j = 0; j < neighbors.length; j++) {
|
for (let j = 0; j < neighbors.length; j++) {
|
||||||
let neighbor = neighbors[j];
|
let neighbor = neighbors[j];
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ module es {
|
|||||||
let didCollide = false;
|
let didCollide = false;
|
||||||
|
|
||||||
// 获取我们在新位置可能发生碰撞的任何东西
|
// 获取我们在新位置可能发生碰撞的任何东西
|
||||||
this.entity.position = Vector2.add(this.entity.position, motion);
|
this.entity.position.add(motion);
|
||||||
|
|
||||||
// 获取任何可能在新位置发生碰撞的东西
|
// 获取任何可能在新位置发生碰撞的东西
|
||||||
let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers);
|
let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers.value);
|
||||||
for (let i = 0; i < neighbors.length; i++) {
|
for (let neighbor of neighbors){
|
||||||
let neighbor = neighbors[i];
|
if (this._collider.overlaps(neighbor) && neighbor.enabled){
|
||||||
if (this._collider.overlaps(neighbor) && neighbor.enabled) {
|
|
||||||
didCollide = true;
|
didCollide = true;
|
||||||
this.notifyTriggerListeners(this._collider, neighbor);
|
this.notifyTriggerListeners(this._collider, neighbor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module es {
|
|||||||
public readonly sprites: Sprite[];
|
public readonly sprites: Sprite[];
|
||||||
public readonly frameRate: number;
|
public readonly frameRate: number;
|
||||||
|
|
||||||
constructor(sprites: Sprite[], frameRate: number) {
|
constructor(sprites: Sprite[], frameRate: number = 10) {
|
||||||
this.sprites = sprites;
|
this.sprites = sprites;
|
||||||
this.frameRate = frameRate;
|
this.frameRate = frameRate;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module es {
|
module es {
|
||||||
export class TiledMapRenderer extends RenderableComponent {
|
export class TiledMapRenderer extends RenderableComponent {
|
||||||
public tiledMap: TmxMap;
|
public tiledMap: TmxMap;
|
||||||
public physicsLayer: number = 1 << 0;
|
public physicsLayer: Ref<number> = new Ref(1 << 0);
|
||||||
/**
|
/**
|
||||||
* 如果空,所有层将被渲染
|
* 如果空,所有层将被渲染
|
||||||
*/
|
*/
|
||||||
@@ -27,7 +27,7 @@ module es {
|
|||||||
this.displayObject = new egret.DisplayObjectContainer();
|
this.displayObject = new egret.DisplayObjectContainer();
|
||||||
|
|
||||||
if (collisionLayerName) {
|
if (collisionLayerName) {
|
||||||
this.collisionLayer = tiledMap.tileLayers[collisionLayerName];
|
this.collisionLayer = tiledMap.tileLayers.find(layer => layer.name == collisionLayerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ module es {
|
|||||||
// 为我们收到的矩形创建碰撞器
|
// 为我们收到的矩形创建碰撞器
|
||||||
this._colliders = [];
|
this._colliders = [];
|
||||||
for (let i = 0; i < collisionRects.length; i++) {
|
for (let i = 0; i < collisionRects.length; i++) {
|
||||||
let collider = new BoxCollider().createBoxRect(collisionRects[i].x + this._localOffset.x,
|
let collider = new BoxCollider(collisionRects[i].x + this._localOffset.x,
|
||||||
collisionRects[i].y + this._localOffset.y, collisionRects[i].width, collisionRects[i].height);
|
collisionRects[i].y + this._localOffset.y, collisionRects[i].width, collisionRects[i].height);
|
||||||
collider.physicsLayer = this.physicsLayer;
|
collider.physicsLayer = this.physicsLayer;
|
||||||
collider.entity = this.entity;
|
collider.entity = this.entity;
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ module es {
|
|||||||
|
|
||||||
// 更新我们所有的系统管理器
|
// 更新我们所有的系统管理器
|
||||||
Time.update(egret.getTimer());
|
Time.update(egret.getTimer());
|
||||||
|
Input.update();
|
||||||
|
|
||||||
if (this._scene) {
|
if (this._scene) {
|
||||||
for (let i = this._globalManagers.length - 1; i >= 0; i--) {
|
for (let i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||||
|
|||||||
@@ -280,20 +280,6 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建此实体的深层克隆。子类可以重写此方法来复制任何自定义字段。
|
|
||||||
* 当重写时,应该调用CopyFrom方法,它将为您克隆所有组件、碰撞器和转换子组件。
|
|
||||||
* 注意克隆的实体不会被添加到任何场景中!你必须自己添加它们!
|
|
||||||
* @param position
|
|
||||||
*/
|
|
||||||
public clone(position: Vector2 = new Vector2()): Entity {
|
|
||||||
let entity = new Entity(this.name + "(clone)");
|
|
||||||
entity.copyFrom(this);
|
|
||||||
entity.transform.position = position;
|
|
||||||
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在提交了所有挂起的实体更改后,将此实体添加到场景时调用
|
* 在提交了所有挂起的实体更改后,将此实体添加到场景时调用
|
||||||
*/
|
*/
|
||||||
@@ -413,31 +399,5 @@ module es {
|
|||||||
public toString(): string {
|
public toString(): string {
|
||||||
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
|
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 将实体的属性、组件和碰撞器复制到此实例
|
|
||||||
* @param entity
|
|
||||||
*/
|
|
||||||
protected copyFrom(entity: Entity) {
|
|
||||||
this.tag = entity.tag;
|
|
||||||
this.updateInterval = entity.updateInterval;
|
|
||||||
this.updateOrder = entity.updateOrder;
|
|
||||||
this.enabled = entity.enabled;
|
|
||||||
|
|
||||||
this.transform.scale = entity.transform.scale;
|
|
||||||
this.transform.rotation = entity.transform.rotation;
|
|
||||||
|
|
||||||
for (let i = 0; i < entity.components.count; i++)
|
|
||||||
this.addComponent(entity.components.buffer[i].clone());
|
|
||||||
for (let i = 0; i < entity.components._componentsToAdd.length; i++)
|
|
||||||
this.addComponent(entity.components._componentsToAdd[i].clone());
|
|
||||||
|
|
||||||
for (let i = 0; i < entity.transform.childCount; i++) {
|
|
||||||
let child = entity.transform.getChild(i).entity;
|
|
||||||
let childClone = child.clone();
|
|
||||||
childClone.transform.copyFrom(child.transform);
|
|
||||||
childClone.transform.parent = this.transform;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ module es {
|
|||||||
* @param self
|
* @param self
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
public static setFlagExclusive(self: number, flag: number) {
|
public static setFlagExclusive(self: Ref<number>, flag: number) {
|
||||||
return 1 << flag;
|
self.value = 1 << flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,8 +39,8 @@ module es {
|
|||||||
* @param self
|
* @param self
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
public static setFlag(self: number, flag: number) {
|
public static setFlag(self: Ref<number>, flag: number) {
|
||||||
return (self | 1 << flag);
|
self.value = (self.value | 1 << flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,17 +48,17 @@ module es {
|
|||||||
* @param self
|
* @param self
|
||||||
* @param flag
|
* @param flag
|
||||||
*/
|
*/
|
||||||
public static unsetFlag(self: number, flag: number) {
|
public static unsetFlag(self: Ref<number>, flag: number) {
|
||||||
flag = 1 << flag;
|
flag = 1 << flag;
|
||||||
return (self & (~flag));
|
self.value = (self.value & (~flag));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 反转数值集合位
|
* 反转数值集合位
|
||||||
* @param self
|
* @param self
|
||||||
*/
|
*/
|
||||||
public static invertFlags(self: number) {
|
public static invertFlags(self: Ref<number>) {
|
||||||
return ~self;
|
self.value = ~self.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,28 +67,51 @@ module es {
|
|||||||
return Vector2.add(lineA, new Vector2(v.x * t, v.y * t));
|
return Vector2.add(lineA, new Vector2(v.x * t, v.y * t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isCircleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean {
|
public static circleToCircle(circleCenter1: Vector2, circleRadius1: number, circleCenter2: Vector2, circleRadius2: number): boolean {
|
||||||
return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2);
|
return Vector2.distanceSquared(circleCenter1, circleCenter2) < (circleRadius1 + circleRadius2) * (circleRadius1 + circleRadius2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isCircleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean {
|
public static circleToLine(circleCenter: Vector2, radius: number, lineFrom: Vector2, lineTo: Vector2): boolean {
|
||||||
return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius;
|
return Vector2.distanceSquared(circleCenter, this.closestPointOnLine(lineFrom, lineTo, circleCenter)) < radius * radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isCircleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean {
|
public static circleToPoint(circleCenter: Vector2, radius: number, point: Vector2): boolean {
|
||||||
return Vector2.distanceSquared(circleCenter, point) < radius * radius;
|
return Vector2.distanceSquared(circleCenter, point) < radius * radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isRectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean {
|
public static rectToCircle(rect: egret.Rectangle, cPosition: Vector2, cRadius: number): boolean {
|
||||||
let ew = rect.width * 0.5;
|
if (this.rectToPoint(rect.x, rect.y, rect.width, rect.height, cPosition))
|
||||||
let eh = rect.height * 0.5;
|
return true;
|
||||||
let vx = Math.max(0, Math.max(cPosition.x - rect.x) - ew);
|
|
||||||
let vy = Math.max(0, Math.max(cPosition.y - rect.y) - eh);
|
|
||||||
|
|
||||||
return vx * vx + vy * vy < cRadius * cRadius;
|
let edgeFrom: Vector2 = Vector2.zero;
|
||||||
|
let edgeTo: Vector2 = Vector2.zero;
|
||||||
|
let sector = this.getSector(rect.x, rect.y, rect.width, rect.height, cPosition);
|
||||||
|
|
||||||
|
if ((sector & PointSectors.top) != 0){
|
||||||
|
edgeFrom = new Vector2(rect.x, rect.y);
|
||||||
|
edgeTo = new Vector2(rect.x + rect.width, rect.y);
|
||||||
|
if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isRectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2) {
|
if ((sector & PointSectors.bottom) != 0){
|
||||||
|
edgeFrom = new Vector2(rect.x, rect.y + rect.width);
|
||||||
|
edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height);
|
||||||
|
if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((sector & PointSectors.left) != 0){
|
||||||
|
edgeFrom = new Vector2(rect.x + rect.width, rect.y);
|
||||||
|
edgeTo = new Vector2(rect.x + rect.width, rect.y + rect.height);
|
||||||
|
if (this.circleToLine(cPosition, cRadius, edgeFrom, edgeTo))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static rectToLine(rect: Rectangle, lineFrom: Vector2, lineTo: Vector2) {
|
||||||
let fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom);
|
let fromSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineFrom);
|
||||||
let toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo);
|
let toSector = this.getSector(rect.x, rect.y, rect.width, rect.height, lineTo);
|
||||||
|
|
||||||
@@ -134,7 +157,7 @@ module es {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isRectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2) {
|
public static rectToPoint(rX: number, rY: number, rW: number, rH: number, point: Vector2) {
|
||||||
return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH;
|
return point.x >= rX && point.y >= rY && point.x < rX + rW && point.y < rY + rH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ module es {
|
|||||||
return this.bounds.intersects(other.bounds);
|
return this.bounds.intersects(other.bounds);
|
||||||
|
|
||||||
if (other instanceof Circle)
|
if (other instanceof Circle)
|
||||||
return Collisions.isRectToCircle(this.bounds, other.position, other.radius);
|
return Collisions.rectToCircle(this.bounds, other.position, other.radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.overlaps(other);
|
return super.overlaps(other);
|
||||||
|
|||||||
@@ -25,21 +25,21 @@ module es {
|
|||||||
// 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角
|
// 为了处理偏移原点的旋转,我们只需要将圆心围绕(0,0)在一个圆上移动,我们的偏移量就是0角
|
||||||
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
|
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
|
||||||
let offsetLength = hasUnitScale ? collider._localOffsetLength : Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
let offsetLength = hasUnitScale ? collider._localOffsetLength : Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||||
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.position = Vector2.add(collider.transform.position, this.center);
|
this.position = Vector2.add(collider.entity.transform.position, this.center);
|
||||||
this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2);
|
this.bounds = new Rectangle(this.position.x - this.radius, this.position.y - this.radius, this.radius * 2, this.radius * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public overlaps(other: Shape) {
|
public overlaps(other: Shape) {
|
||||||
let result: CollisionResult = new CollisionResult();
|
let result: CollisionResult = new CollisionResult();
|
||||||
if (other instanceof Box && (other as Box).isUnrotated)
|
if (other instanceof Box && (other as Box).isUnrotated)
|
||||||
return Collisions.isRectToCircle(other.bounds, this.position, this.radius);
|
return Collisions.rectToCircle(other.bounds, this.position, this.radius);
|
||||||
|
|
||||||
if (other instanceof Circle)
|
if (other instanceof Circle)
|
||||||
return Collisions.isCircleToCircle(this.position, this.radius, other.position, (other as Circle).radius);
|
return Collisions.circleToCircle(this.position, this.radius, other.position, (other as Circle).radius);
|
||||||
|
|
||||||
if (other instanceof Polygon)
|
if (other instanceof Polygon)
|
||||||
return ShapeCollisions.circleToPolygon(this, other, result);
|
return ShapeCollisions.circleToPolygon(this, other, result);
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ module es {
|
|||||||
public buildEdgeNormals() {
|
public buildEdgeNormals() {
|
||||||
// 对于box 我们只需要两条边,因为另外两条边是平行的
|
// 对于box 我们只需要两条边,因为另外两条边是平行的
|
||||||
let totalEdges = this.isBox ? 2 : this.points.length;
|
let totalEdges = this.isBox ? 2 : this.points.length;
|
||||||
if (this._edgeNormals == null || this._edgeNormals.length != totalEdges)
|
if (this._edgeNormals == undefined || this._edgeNormals.length != totalEdges)
|
||||||
this._edgeNormals = new Array(totalEdges);
|
this._edgeNormals = new Array(totalEdges);
|
||||||
|
|
||||||
let p2: Vector2;
|
let p2: Vector2;
|
||||||
@@ -169,7 +169,7 @@ module es {
|
|||||||
edgeNormal.y = 0;
|
edgeNormal.y = 0;
|
||||||
let closestPoint = new Vector2(0, 0);
|
let closestPoint = new Vector2(0, 0);
|
||||||
|
|
||||||
let tempDistanceSquared;
|
let tempDistanceSquared = 0;
|
||||||
for (let i = 0; i < points.length; i++) {
|
for (let i = 0; i < points.length; i++) {
|
||||||
let j = i + 1;
|
let j = i + 1;
|
||||||
if (j == points.length)
|
if (j == points.length)
|
||||||
@@ -200,9 +200,9 @@ module es {
|
|||||||
* @param originalPoints
|
* @param originalPoints
|
||||||
* @param rotatedPoints
|
* @param rotatedPoints
|
||||||
*/
|
*/
|
||||||
public static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints){
|
public static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: Vector2[]){
|
||||||
let cos = Math.cos(radians);
|
let cos = Math.cos(radians);
|
||||||
let sin = Math.sign(radians);
|
let sin = Math.sin(radians);
|
||||||
|
|
||||||
for (let i = 0; i < originalPoints.length; i ++){
|
for (let i = 0; i < originalPoints.length; i ++){
|
||||||
let position = originalPoints[i];
|
let position = originalPoints[i];
|
||||||
|
|||||||
@@ -26,9 +26,5 @@ module es {
|
|||||||
public abstract containsPoint(point: Vector2);
|
public abstract containsPoint(point: Vector2);
|
||||||
|
|
||||||
public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
public abstract pointCollidesWithShape(point: Vector2, result: CollisionResult): boolean;
|
||||||
|
|
||||||
public clone(): Shape {
|
|
||||||
return ObjectUtils.clone<Shape>(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ module es {
|
|||||||
let collider = cell[i];
|
let collider = cell[i];
|
||||||
|
|
||||||
// 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器
|
// 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器
|
||||||
if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
|
if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer.value))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (bounds.intersects(collider.bounds)) {
|
if (bounds.intersects(collider.bounds)) {
|
||||||
@@ -364,7 +364,7 @@ module es {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 确保碰撞器在图层蒙版上
|
// 确保碰撞器在图层蒙版上
|
||||||
if (!Flags.isFlagSet(this._layerMask, potential.physicsLayer))
|
if (!Flags.isFlagSet(this._layerMask, potential.physicsLayer.value))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO: rayIntersects的性能够吗?需要测试它。Collisions.rectToLine可能更快
|
// TODO: rayIntersects的性能够吗?需要测试它。Collisions.rectToLine可能更快
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ module es {
|
|||||||
* 返回平铺空间中的矩形列表,其中任何非空平铺组合为边界区域
|
* 返回平铺空间中的矩形列表,其中任何非空平铺组合为边界区域
|
||||||
*/
|
*/
|
||||||
public getCollisionRectangles(): Rectangle[] {
|
public getCollisionRectangles(): Rectangle[] {
|
||||||
let checkedIndexes = [];
|
let checkedIndexes: boolean[] = new Array(this.tiles.length);
|
||||||
let rectangles = [];
|
let rectangles = [];
|
||||||
let startCol = -1;
|
let startCol = -1;
|
||||||
let index = -1;
|
let index = -1;
|
||||||
@@ -60,7 +60,7 @@ module es {
|
|||||||
if (startCol < 0)
|
if (startCol < 0)
|
||||||
startCol = x;
|
startCol = x;
|
||||||
checkedIndexes[index] = true;
|
checkedIndexes[index] = true;
|
||||||
}else if(tile || checkedIndexes[index]){
|
}else if(!tile || checkedIndexes[index] == true){
|
||||||
if (startCol >= 0){
|
if (startCol >= 0){
|
||||||
rectangles.push(this.findBoundsRect(startCol, x, y, checkedIndexes));
|
rectangles.push(this.findBoundsRect(startCol, x, y, checkedIndexes));
|
||||||
startCol = -1;
|
startCol = -1;
|
||||||
@@ -90,7 +90,7 @@ module es {
|
|||||||
for (let x = startX; x < endX; x ++){
|
for (let x = startX; x < endX; x ++){
|
||||||
index = y * this.map.width + x;
|
index = y * this.map.width + x;
|
||||||
let tile = this.getTile(x, y);
|
let tile = this.getTile(x, y);
|
||||||
if (tile || checkedIndexes[index]){
|
if (!tile || checkedIndexes[index]){
|
||||||
// 再次将我们到目前为止在这一行中访问过的所有内容设置为false,因为它不会包含在矩形中,应该再次进行检查
|
// 再次将我们到目前为止在这一行中访问过的所有内容设置为false,因为它不会包含在矩形中,应该再次进行检查
|
||||||
for (let _x = startX; _x < x; _x++){
|
for (let _x = startX; _x < x; _x++){
|
||||||
index = y * this.map.width + _x;
|
index = y * this.map.width + _x;
|
||||||
@@ -132,7 +132,7 @@ module es {
|
|||||||
* TmxTilesetTile只存在于动态的tiles和带有附加属性的tiles中。
|
* TmxTilesetTile只存在于动态的tiles和带有附加属性的tiles中。
|
||||||
*/
|
*/
|
||||||
public get tilesetTile(): TmxTilesetTile {
|
public get tilesetTile(): TmxTilesetTile {
|
||||||
if (this._tilesetTileIndex == undefined){
|
if (!this._tilesetTileIndex){
|
||||||
this._tilesetTileIndex = -1;
|
this._tilesetTileIndex = -1;
|
||||||
if (this.tileset.firstGid <= this.gid){
|
if (this.tileset.firstGid <= this.gid){
|
||||||
let tilesetTile = this.tileset.tiles.get(this.gid - this.tileset.firstGid);
|
let tilesetTile = this.tileset.tiles.get(this.gid - this.tileset.firstGid);
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ module es {
|
|||||||
return this._gameTouchs[0].position;
|
return this._gameTouchs[0].position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static _virtualInputs: VirtualInput[] = [];
|
||||||
|
|
||||||
/** 获取最大触摸数 */
|
/** 获取最大触摸数 */
|
||||||
public static get maxSupportedTouch() {
|
public static get maxSupportedTouch() {
|
||||||
return Core._instance.stage.maxTouches;
|
return Core._instance.stage.maxTouches;
|
||||||
@@ -91,11 +93,45 @@ module es {
|
|||||||
this.initTouchCache();
|
this.initTouchCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static update(){
|
||||||
|
KeyboardUtils.update();
|
||||||
|
for (let i = 0; i < this._virtualInputs.length; i ++)
|
||||||
|
this._virtualInputs[i].update();
|
||||||
|
}
|
||||||
|
|
||||||
public static scaledPosition(position: Vector2) {
|
public static scaledPosition(position: Vector2) {
|
||||||
let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
|
let scaledPos = new Vector2(position.x - this._resolutionOffset.x, position.y - this._resolutionOffset.y);
|
||||||
return Vector2.multiply(scaledPos, this.resolutionScale);
|
return Vector2.multiply(scaledPos, this.resolutionScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只有在当前帧按下并且在上一帧没有按下时才算press
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public static isKeyPressed(key: Keys): boolean{
|
||||||
|
return KeyboardUtils.currentKeys.contains(key) && !KeyboardUtils.previousKeys.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static isKeyPressedBoth(keyA: Keys, keyB: Keys){
|
||||||
|
return this.isKeyPressed(keyA) || this.isKeyPressed(keyB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static isKeyDown(key: Keys): boolean {
|
||||||
|
return KeyboardUtils.currentKeys.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static isKeyDownBoth(keyA: Keys, keyB: Keys){
|
||||||
|
return this.isKeyDown(keyA) || this.isKeyDown(keyB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static isKeyReleased(key: Keys){
|
||||||
|
return !KeyboardUtils.currentKeys.contains(key) && KeyboardUtils.previousKeys.contains(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static isKeyReleasedBoth(keyA: Keys, keyB: Keys){
|
||||||
|
return this.isKeyReleased(keyA) || this.isKeyReleased(keyB);
|
||||||
|
}
|
||||||
|
|
||||||
private static initTouchCache() {
|
private static initTouchCache() {
|
||||||
this._totalTouchCount = 0;
|
this._totalTouchCount = 0;
|
||||||
this._touchIndex = 0;
|
this._touchIndex = 0;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import Keys = es.Keys;
|
||||||
|
|
||||||
|
class KeyboardUtils {
|
||||||
|
/**
|
||||||
|
* 当前帧按键状态
|
||||||
|
*/
|
||||||
|
public static currentKeys: Keys[] = [];
|
||||||
|
/**
|
||||||
|
* 上一帧按键状态
|
||||||
|
*/
|
||||||
|
public static previousKeys: Keys[] = [];
|
||||||
|
private static keyStatusKeys: Keys[] = [];
|
||||||
|
|
||||||
|
public static init(): void {
|
||||||
|
document.addEventListener("keydown", KeyboardUtils.onKeyDownHandler);
|
||||||
|
document.addEventListener("keyup", KeyboardUtils.onKeyUpHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static update(){
|
||||||
|
KeyboardUtils.previousKeys.length = 0;
|
||||||
|
for (let key of KeyboardUtils.currentKeys){
|
||||||
|
KeyboardUtils.previousKeys.push(key);
|
||||||
|
KeyboardUtils.currentKeys.remove(key);
|
||||||
|
}
|
||||||
|
KeyboardUtils.currentKeys.length = 0;
|
||||||
|
for (let key of KeyboardUtils.keyStatusKeys){
|
||||||
|
KeyboardUtils.currentKeys.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static destroy(): void {
|
||||||
|
KeyboardUtils.currentKeys.length = 0;
|
||||||
|
|
||||||
|
document.removeEventListener("keyup", KeyboardUtils.onKeyUpHandler);
|
||||||
|
document.removeEventListener("keypress", KeyboardUtils.onKeyDownHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static onKeyDownHandler(event: KeyboardEvent): void {
|
||||||
|
if (!KeyboardUtils.keyStatusKeys.contains(event.keyCode))
|
||||||
|
KeyboardUtils.keyStatusKeys.push(event.keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static onKeyUpHandler(event: KeyboardEvent): void {
|
||||||
|
if (KeyboardUtils.keyStatusKeys.contains(event.keyCode))
|
||||||
|
KeyboardUtils.keyStatusKeys.remove(event.keyCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
module es {
|
||||||
|
export enum Keys {
|
||||||
|
none,
|
||||||
|
back = 8,
|
||||||
|
tab = 9,
|
||||||
|
enter = 13,
|
||||||
|
capsLock = 20,
|
||||||
|
escape = 27,
|
||||||
|
space = 32,
|
||||||
|
pageUp = 33,
|
||||||
|
pageDown = 34,
|
||||||
|
end = 35,
|
||||||
|
home = 36,
|
||||||
|
left = 37,
|
||||||
|
up = 38,
|
||||||
|
right = 39,
|
||||||
|
down = 40,
|
||||||
|
select = 41,
|
||||||
|
print = 42,
|
||||||
|
execute = 43,
|
||||||
|
printScreen = 44,
|
||||||
|
insert = 45,
|
||||||
|
delete = 46,
|
||||||
|
help = 47,
|
||||||
|
d0 = 48,
|
||||||
|
d1 = 49,
|
||||||
|
d2 = 50,
|
||||||
|
d3 = 51,
|
||||||
|
d4 = 52,
|
||||||
|
d5 = 53,
|
||||||
|
d6 = 54,
|
||||||
|
d7 = 55,
|
||||||
|
d8 = 56,
|
||||||
|
d9 = 57,
|
||||||
|
a = 65,
|
||||||
|
b = 66,
|
||||||
|
c = 67,
|
||||||
|
d = 68,
|
||||||
|
e = 69,
|
||||||
|
f = 70,
|
||||||
|
g = 71,
|
||||||
|
h = 72,
|
||||||
|
i = 73,
|
||||||
|
j = 74,
|
||||||
|
k = 75,
|
||||||
|
l = 76,
|
||||||
|
m = 77,
|
||||||
|
n = 78,
|
||||||
|
o = 79,
|
||||||
|
p = 80,
|
||||||
|
q = 81,
|
||||||
|
r = 82,
|
||||||
|
s = 83,
|
||||||
|
t = 84,
|
||||||
|
u = 85,
|
||||||
|
v = 86,
|
||||||
|
w = 87,
|
||||||
|
x = 88,
|
||||||
|
y = 89,
|
||||||
|
z = 90,
|
||||||
|
leftWindows = 91,
|
||||||
|
rightWindows = 92,
|
||||||
|
apps = 93,
|
||||||
|
sleep = 95,
|
||||||
|
numPad0 = 96,
|
||||||
|
numPad1 = 97,
|
||||||
|
numPad2 = 98,
|
||||||
|
numPad3 = 99,
|
||||||
|
numPad4 = 100,
|
||||||
|
numPad5 = 101,
|
||||||
|
numPad6 = 102,
|
||||||
|
numPad7 = 103,
|
||||||
|
numPad8 = 104,
|
||||||
|
numPad9 = 105,
|
||||||
|
multiply = 106,
|
||||||
|
add = 107,
|
||||||
|
seperator = 108,
|
||||||
|
subtract = 109,
|
||||||
|
decimal = 110,
|
||||||
|
divide = 111,
|
||||||
|
f1 = 112,
|
||||||
|
f2 = 113,
|
||||||
|
f3 = 114,
|
||||||
|
f4 = 115,
|
||||||
|
f5 = 116,
|
||||||
|
f6 = 117,
|
||||||
|
f7 = 118,
|
||||||
|
f8 = 119,
|
||||||
|
f9 = 120,
|
||||||
|
f10 = 121,
|
||||||
|
f11 = 122,
|
||||||
|
f12 = 123,
|
||||||
|
f13 = 124,
|
||||||
|
f14 = 125,
|
||||||
|
f15 = 126,
|
||||||
|
f16 = 127,
|
||||||
|
f17 = 128,
|
||||||
|
f18 = 129,
|
||||||
|
f19 = 130,
|
||||||
|
f20 = 131,
|
||||||
|
f21 = 132,
|
||||||
|
f22 = 133,
|
||||||
|
f23 = 134,
|
||||||
|
f24 = 135,
|
||||||
|
numLock = 144,
|
||||||
|
scroll = 145,
|
||||||
|
leftShift = 160,
|
||||||
|
rightShift = 161,
|
||||||
|
leftControl = 162,
|
||||||
|
rightControl = 163,
|
||||||
|
leftAlt = 164,
|
||||||
|
rightAlt = 165,
|
||||||
|
browserBack = 166,
|
||||||
|
browserForward = 167
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
///<reference path="VirtualInput.ts"/>
|
||||||
|
///<reference path="VirtualIntegerAxis.ts"/>
|
||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 用-1和1之间的浮点数表示的虚拟输入
|
||||||
|
*/
|
||||||
|
export class VirtualAxis extends VirtualInput {
|
||||||
|
public nodes: VirtualAxisNode[] = [];
|
||||||
|
|
||||||
|
public get value() {
|
||||||
|
for (let i = 0; i < this.nodes.length; i++) {
|
||||||
|
let val = this.nodes[i].value;
|
||||||
|
if (val != 0)
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(...nodes: VirtualAxisNode[]) {
|
||||||
|
super();
|
||||||
|
this.nodes.concat(nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
for (let i = 0; i < this.nodes.length; i++)
|
||||||
|
this.nodes[i].update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class KeyboardKeys extends VirtualAxisNode {
|
||||||
|
public overlapBehavior: OverlapBehavior;
|
||||||
|
public positive: Keys;
|
||||||
|
public negative: Keys;
|
||||||
|
public _value: number = 0;
|
||||||
|
public _turned: boolean;
|
||||||
|
|
||||||
|
constructor(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys) {
|
||||||
|
super();
|
||||||
|
this.overlapBehavior = overlapBehavior;
|
||||||
|
this.negative = negative;
|
||||||
|
this.positive = positive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
if (Input.isKeyDown(this.positive)) {
|
||||||
|
if (Input.isKeyDown(this.negative)) {
|
||||||
|
switch (this.overlapBehavior) {
|
||||||
|
default:
|
||||||
|
case es.OverlapBehavior.cancelOut:
|
||||||
|
this._value = 0;
|
||||||
|
break;
|
||||||
|
case es.OverlapBehavior.takeNewer:
|
||||||
|
if (!this._turned) {
|
||||||
|
this._value *= -1;
|
||||||
|
this._turned = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case es.OverlapBehavior.takeOlder:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this._turned = false;
|
||||||
|
this._value = 1;
|
||||||
|
}
|
||||||
|
} else if (Input.isKeyDown(this.negative)) {
|
||||||
|
this._turned = false;
|
||||||
|
this._value = -1;
|
||||||
|
} else {
|
||||||
|
this._turned = false;
|
||||||
|
this._value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public get value(){
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
///<reference path="./VirtualInput.ts" />
|
||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 用布尔值表示的虚拟输入。除了简单地检查当前按钮状态,
|
||||||
|
* 您还可以询问它是否刚刚被按下或释放了这个框架。
|
||||||
|
* 您还可以将按下的按钮存储在缓冲区中一段有限的时间,或者直到调用consumeBuffer()将其使用为止。
|
||||||
|
*/
|
||||||
|
export class VirtualButton extends VirtualInput{
|
||||||
|
public nodes: Node[] = [];
|
||||||
|
public bufferTime: number = 0;
|
||||||
|
public firstRepeatTime: number = 0;
|
||||||
|
public mutiRepeatTime: number = 0;
|
||||||
|
public isRepeating: boolean;
|
||||||
|
|
||||||
|
public _bufferCounter: number = 0;
|
||||||
|
public _repeatCounter: number = 0;
|
||||||
|
public _willRepeat: boolean;
|
||||||
|
|
||||||
|
constructor(bufferTime: number = 0, ...nodes: Node[]){
|
||||||
|
super();
|
||||||
|
this.nodes = nodes;
|
||||||
|
this.bufferTime = bufferTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setRepeat(firstRepeatTime: number, mutiRepeatTime: number = firstRepeatTime){
|
||||||
|
this.firstRepeatTime = firstRepeatTime;
|
||||||
|
this.mutiRepeatTime = mutiRepeatTime;
|
||||||
|
this._willRepeat = this.firstRepeatTime > 0;
|
||||||
|
if (!this._willRepeat)
|
||||||
|
this.isRepeating = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
this._bufferCounter -= Time.unscaledDeltaTime;
|
||||||
|
this.isRepeating = false;
|
||||||
|
|
||||||
|
let check = false;
|
||||||
|
for (let i = 0; i < this.nodes.length; i ++){
|
||||||
|
this.nodes[i].update();
|
||||||
|
if (this.nodes[i].isPressed){
|
||||||
|
this._bufferCounter = this.bufferTime;
|
||||||
|
check = true;
|
||||||
|
}else if(this.nodes[i].isDown){
|
||||||
|
check = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!check){
|
||||||
|
this._repeatCounter = 0;
|
||||||
|
this._bufferCounter = 0;
|
||||||
|
}else if(this._willRepeat){
|
||||||
|
if (this._repeatCounter == 0){
|
||||||
|
this._repeatCounter = this.firstRepeatTime;
|
||||||
|
}else{
|
||||||
|
this._repeatCounter -= Time.unscaledDeltaTime;
|
||||||
|
if (this._repeatCounter <= 0){
|
||||||
|
this.isRepeating = true;
|
||||||
|
this._repeatCounter = this.mutiRepeatTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isDown(){
|
||||||
|
for (let node of this.nodes){
|
||||||
|
if (node.isDown)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isPressed(){
|
||||||
|
if (this._bufferCounter > 0 || this.isRepeating)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (let node of this.nodes){
|
||||||
|
if (node.isPressed)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isReleased(){
|
||||||
|
for (let node of this.nodes){
|
||||||
|
if (node.isReleased)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public consumeBuffer(){
|
||||||
|
this._bufferCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加一个键盘键到这个虚拟按钮
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public addKeyboardKey(key: Keys): VirtualButton{
|
||||||
|
this.nodes.push(new KeyboardKey(key));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class Node extends VirtualInputNode {
|
||||||
|
public abstract isDown: boolean;
|
||||||
|
public abstract isPressed: boolean;
|
||||||
|
public abstract isReleased: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class KeyboardKey extends Node {
|
||||||
|
public key: Keys;
|
||||||
|
|
||||||
|
constructor(key: Keys){
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isDown(){
|
||||||
|
return Input.isKeyDown(this.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isPressed(){
|
||||||
|
return Input.isKeyPressed(this.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public get isReleased(){
|
||||||
|
return Input.isKeyReleased(this.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
module es {
|
||||||
|
export enum OverlapBehavior {
|
||||||
|
/**
|
||||||
|
* 重复的输入将导致相互抵消,并且不会记录任何输入。
|
||||||
|
* 例如:按左箭头键,按住时按右箭头键。这将导致相互抵消。
|
||||||
|
*/
|
||||||
|
cancelOut,
|
||||||
|
/**
|
||||||
|
* 将使用找到的第一个输入
|
||||||
|
*/
|
||||||
|
takeOlder,
|
||||||
|
/**
|
||||||
|
* 将使用找到的最后一个输入
|
||||||
|
*/
|
||||||
|
takeNewer,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 虚拟按钮,其状态由其VirtualInputNodes的状态决定
|
||||||
|
*/
|
||||||
|
export abstract class VirtualInput {
|
||||||
|
protected constructor() {
|
||||||
|
Input._virtualInputs.push(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从输入系统取消虚拟输入的注册。在轮询VirtualInput之后调用这个函数
|
||||||
|
*/
|
||||||
|
public deregister(){
|
||||||
|
Input._virtualInputs.remove(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将它们添加到您的VirtualInput中,以定义它如何确定当前输入状态。
|
||||||
|
* 例如,如果你想检查一个键盘键是否被按下,创建一个VirtualButton并添加一个VirtualButton.keyboardkey
|
||||||
|
*/
|
||||||
|
export abstract class VirtualInputNode {
|
||||||
|
public update() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
module es {
|
||||||
|
/**
|
||||||
|
* 用int(-1、0或1)表示的虚拟输入。它对应的输入可以从上到下到下,
|
||||||
|
* 如使用两个键盘键作为正/负检查。
|
||||||
|
*/
|
||||||
|
export class VirtualIntegerAxis extends VirtualInput {
|
||||||
|
public nodes: VirtualAxisNode[] = [];
|
||||||
|
|
||||||
|
public get value(){
|
||||||
|
for (let i = 0; i < this.nodes.length; i ++){
|
||||||
|
let val = this.nodes[i].value;
|
||||||
|
if (val != 0)
|
||||||
|
return Math.sign(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(...nodes: VirtualAxisNode[]){
|
||||||
|
super();
|
||||||
|
this.nodes.concat(nodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
for (let i = 0; i < this.nodes.length; i ++)
|
||||||
|
this.nodes[i].update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加键盘键来模拟这个虚拟输入的左/右或上/下
|
||||||
|
* @param overlapBehavior
|
||||||
|
* @param negative
|
||||||
|
* @param positive
|
||||||
|
*/
|
||||||
|
public addKeyboardKeys(overlapBehavior: OverlapBehavior, negative: Keys, positive: Keys){
|
||||||
|
this.nodes.push(new KeyboardKeys(overlapBehavior, negative, positive));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class VirtualAxisNode extends VirtualInputNode {
|
||||||
|
public abstract value: number;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,225 +0,0 @@
|
|||||||
class KeyboardUtils {
|
|
||||||
/**
|
|
||||||
* 键盘事件类型
|
|
||||||
*/
|
|
||||||
public static TYPE_KEY_DOWN: number = 0;
|
|
||||||
public static TYPE_KEY_UP: number = 1;
|
|
||||||
/**
|
|
||||||
* 键值字符串枚举
|
|
||||||
*/
|
|
||||||
public static A: string = "A";
|
|
||||||
public static B: string = "B";
|
|
||||||
public static C: string = "C";
|
|
||||||
public static D: string = "D";
|
|
||||||
public static E: string = "E";
|
|
||||||
public static F: string = "F";
|
|
||||||
public static G: string = "G";
|
|
||||||
public static H: string = "H";
|
|
||||||
public static I: string = "I";
|
|
||||||
public static J: string = "J";
|
|
||||||
public static K: string = "K";
|
|
||||||
public static L: string = "L";
|
|
||||||
public static M: string = "M";
|
|
||||||
public static N: string = "N";
|
|
||||||
public static O: string = "O";
|
|
||||||
public static P: string = "P";
|
|
||||||
public static Q: string = "Q";
|
|
||||||
public static R: string = "R";
|
|
||||||
public static S: string = "S";
|
|
||||||
public static T: string = "T";
|
|
||||||
public static U: string = "U";
|
|
||||||
public static V: string = "V";
|
|
||||||
public static W: string = "W";
|
|
||||||
public static X: string = "X";
|
|
||||||
public static Y: string = "Y";
|
|
||||||
public static Z: string = "Z";
|
|
||||||
public static ESC: string = "Esc";
|
|
||||||
public static F1: string = "F1";
|
|
||||||
public static F2: string = "F2";
|
|
||||||
public static F3: string = "F3";
|
|
||||||
public static F4: string = "F4";
|
|
||||||
public static F5: string = "F5";
|
|
||||||
public static F6: string = "F6";
|
|
||||||
public static F7: string = "F7";
|
|
||||||
public static F8: string = "F8";
|
|
||||||
public static F9: string = "F9";
|
|
||||||
public static F10: string = "F10";
|
|
||||||
public static F11: string = "F11";
|
|
||||||
public static F12: string = "F12";
|
|
||||||
public static NUM_1: string = "1";
|
|
||||||
public static NUM_2: string = "2";
|
|
||||||
public static NUM_3: string = "3";
|
|
||||||
public static NUM_4: string = "4";
|
|
||||||
public static NUM_5: string = "5";
|
|
||||||
public static NUM_6: string = "6";
|
|
||||||
public static NUM_7: string = "7";
|
|
||||||
public static NUM_8: string = "8";
|
|
||||||
public static NUM_9: string = "9";
|
|
||||||
public static NUM_0: string = "0";
|
|
||||||
public static TAB: string = "Tab";
|
|
||||||
public static CTRL: string = "Ctrl";
|
|
||||||
public static ALT: string = "Alt";
|
|
||||||
public static SHIFT: string = "Shift";
|
|
||||||
public static CAPS_LOCK: string = "Caps Lock";
|
|
||||||
public static ENTER: string = "Enter";
|
|
||||||
public static SPACE: string = "Space";
|
|
||||||
public static BACK_SPACE: string = "Back Space";
|
|
||||||
public static INSERT: string = "Insert";
|
|
||||||
public static DELETE: string = "Page Down";
|
|
||||||
public static HOME: string = "Home";
|
|
||||||
public static END: string = "Page Down";
|
|
||||||
public static PAGE_UP: string = "Page Up";
|
|
||||||
public static PAGE_DOWN: string = "Page Down";
|
|
||||||
public static LEFT: string = "Left";
|
|
||||||
public static RIGHT: string = "Right";
|
|
||||||
public static UP: string = "Up";
|
|
||||||
public static DOWN: string = "Down";
|
|
||||||
public static PAUSE_BREAK: string = "Pause Break";
|
|
||||||
public static NUM_LOCK: string = "Num Lock";
|
|
||||||
public static SCROLL_LOCK: string = "Scroll Lock";
|
|
||||||
public static WINDOWS: string = "Windows";
|
|
||||||
//存放按下注册数据的字典
|
|
||||||
private static keyDownDict: Object;
|
|
||||||
//存放按起注册数据的字典
|
|
||||||
private static keyUpDict: Object;
|
|
||||||
|
|
||||||
public static init(): void {
|
|
||||||
KeyboardUtils.keyDownDict = {};
|
|
||||||
KeyboardUtils.keyUpDict = {};
|
|
||||||
document.addEventListener("keydown", KeyboardUtils.onKeyDonwHander);
|
|
||||||
document.addEventListener("keyup", KeyboardUtils.onKeyUpHander);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册按键
|
|
||||||
* @param key 键值
|
|
||||||
* @param fun 回调方法
|
|
||||||
* @param type 按键类型 TYPE_KEY_DOWN、TYPE_KEY_UP
|
|
||||||
*/
|
|
||||||
public static registerKey(key: string, fun: Function, thisObj: any, type: number = 0, ...args): void {
|
|
||||||
var keyDict: Object = type ? this.keyUpDict : this.keyDownDict;
|
|
||||||
keyDict[key] = {"fun": fun, args: args, "thisObj": thisObj};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注销按键
|
|
||||||
* @param key 键值
|
|
||||||
* @param type 注销的类型
|
|
||||||
*/
|
|
||||||
public static unregisterKey(key: string, type: number = 0): void {
|
|
||||||
var keyDict: Object = type ? this.keyUpDict : this.keyDownDict;
|
|
||||||
delete keyDict[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 销毁方法
|
|
||||||
*/
|
|
||||||
public static destroy(): void {
|
|
||||||
KeyboardUtils.keyDownDict = null;
|
|
||||||
KeyboardUtils.keyUpDict = null;
|
|
||||||
document.removeEventListener("keydown", this.onKeyDonwHander);
|
|
||||||
document.removeEventListener("keyup", this.onKeyUpHander);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onKeyDonwHander(event: KeyboardEvent): void {
|
|
||||||
if (!KeyboardUtils.keyDownDict) return;
|
|
||||||
var key: string = KeyboardUtils.keyCodeToString(event.keyCode);
|
|
||||||
var o: Object = KeyboardUtils.keyDownDict[key];
|
|
||||||
if (o) {
|
|
||||||
var fun: Function = o["fun"];
|
|
||||||
var thisObj: any = o["thisObj"];
|
|
||||||
var args: any = o["args"];
|
|
||||||
fun.apply(thisObj, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static onKeyUpHander(event: KeyboardEvent): void {
|
|
||||||
if (!KeyboardUtils.keyUpDict) return;
|
|
||||||
var key: string = KeyboardUtils.keyCodeToString(event.keyCode);
|
|
||||||
var o: Object = KeyboardUtils.keyUpDict[key];
|
|
||||||
if (o) {
|
|
||||||
var fun: Function = o["fun"];
|
|
||||||
var thisObj: any = o["thisObj"];
|
|
||||||
var args: any = o["args"];
|
|
||||||
fun.apply(thisObj, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据keyCode或charCode获取相应的字符串代号
|
|
||||||
* @param keyCode
|
|
||||||
* @return 键盘所指字符串代号
|
|
||||||
*/
|
|
||||||
private static keyCodeToString(keyCode: number): string {
|
|
||||||
switch (keyCode) {
|
|
||||||
case 8:
|
|
||||||
return this.BACK_SPACE;
|
|
||||||
case 9:
|
|
||||||
return this.TAB;
|
|
||||||
case 13:
|
|
||||||
return this.ENTER;
|
|
||||||
case 16:
|
|
||||||
return this.SHIFT;
|
|
||||||
case 17:
|
|
||||||
return this.CTRL;
|
|
||||||
case 19:
|
|
||||||
return this.PAUSE_BREAK;
|
|
||||||
case 20:
|
|
||||||
return this.CAPS_LOCK;
|
|
||||||
case 27:
|
|
||||||
return this.ESC;
|
|
||||||
case 32:
|
|
||||||
return this.SPACE;
|
|
||||||
case 33:
|
|
||||||
return this.PAGE_UP;
|
|
||||||
case 34:
|
|
||||||
return this.PAGE_DOWN;
|
|
||||||
case 35:
|
|
||||||
return this.END;
|
|
||||||
case 36:
|
|
||||||
return this.HOME;
|
|
||||||
case 37:
|
|
||||||
return this.LEFT;
|
|
||||||
case 38:
|
|
||||||
return this.UP;
|
|
||||||
case 39:
|
|
||||||
return this.RIGHT;
|
|
||||||
case 40:
|
|
||||||
return this.DOWN;
|
|
||||||
case 45:
|
|
||||||
return this.INSERT;
|
|
||||||
case 46:
|
|
||||||
return this.DELETE;
|
|
||||||
case 91:
|
|
||||||
return this.WINDOWS;
|
|
||||||
case 112:
|
|
||||||
return this.F1;
|
|
||||||
case 113:
|
|
||||||
return this.F2;
|
|
||||||
case 114:
|
|
||||||
return this.F3;
|
|
||||||
case 115:
|
|
||||||
return this.F4;
|
|
||||||
case 116:
|
|
||||||
return this.F5;
|
|
||||||
case 117:
|
|
||||||
return this.F6;
|
|
||||||
case 118:
|
|
||||||
return this.F7;
|
|
||||||
case 119:
|
|
||||||
return this.F8;
|
|
||||||
case 120:
|
|
||||||
return this.F9;
|
|
||||||
case 122:
|
|
||||||
return this.F11;
|
|
||||||
case 123:
|
|
||||||
return this.F12;
|
|
||||||
case 144:
|
|
||||||
return this.NUM_LOCK;
|
|
||||||
case 145:
|
|
||||||
return this.SCROLL_LOCK;
|
|
||||||
default:
|
|
||||||
return String.fromCharCode(keyCode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user