Skip to content

Commit

Permalink
camera.mapSize 支持左上顶点更改
Browse files Browse the repository at this point in the history
  • Loading branch information
esengine committed Aug 8, 2020
1 parent a39b98b commit 14b70b3
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion demo/libs/framework/framework.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ declare module es {
deadzone: Rectangle;
focusOffset: Vector2;
mapLockEnabled: boolean;
mapSize: Vector2;
mapSize: Rectangle;
_targetEntity: Entity;
_targetCollider: Collider;
_desiredPositionDelta: Vector2;
Expand Down
6 changes: 3 additions & 3 deletions demo/libs/framework/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ var es;
_this.deadzone = new es.Rectangle();
_this.focusOffset = es.Vector2.zero;
_this.mapLockEnabled = false;
_this.mapSize = es.Vector2.zero;
_this.mapSize = new es.Rectangle();
_this._desiredPositionDelta = new es.Vector2();
_this._worldSpaceDeadZone = new es.Rectangle();
_this._minimumZoom = 0.3;
Expand Down Expand Up @@ -2415,8 +2415,8 @@ var es;
}
};
Camera.prototype.clampToMapSize = function (position) {
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
return es.Vector2.clamp(position, halfScreen, cameraMax);
};
Camera.prototype.updateFollow = function () {
Expand Down
2 changes: 1 addition & 1 deletion demo/libs/framework/framework.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion source/bin/framework.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ declare module es {
deadzone: Rectangle;
focusOffset: Vector2;
mapLockEnabled: boolean;
mapSize: Vector2;
mapSize: Rectangle;
_targetEntity: Entity;
_targetCollider: Collider;
_desiredPositionDelta: Vector2;
Expand Down
6 changes: 3 additions & 3 deletions source/bin/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,7 @@ var es;
_this.deadzone = new es.Rectangle();
_this.focusOffset = es.Vector2.zero;
_this.mapLockEnabled = false;
_this.mapSize = es.Vector2.zero;
_this.mapSize = new es.Rectangle();
_this._desiredPositionDelta = new es.Vector2();
_this._worldSpaceDeadZone = new es.Rectangle();
_this._minimumZoom = 0.3;
Expand Down Expand Up @@ -2415,8 +2415,8 @@ var es;
}
};
Camera.prototype.clampToMapSize = function (position) {
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
return es.Vector2.clamp(position, halfScreen, cameraMax);
};
Camera.prototype.updateFollow = function () {
Expand Down
2 changes: 1 addition & 1 deletion source/bin/framework.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions source/src/ECS/Components/Camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module es {
/**
* 當前地圖映射的寬度和高度
*/
public mapSize: Vector2 = Vector2.zero;
public mapSize: Rectangle = new Rectangle();
public _targetEntity: Entity;
public _targetCollider: Collider;
public _desiredPositionDelta: Vector2 = new Vector2();
Expand Down Expand Up @@ -385,8 +385,8 @@ module es {
* @param position
*/
public clampToMapSize(position: Vector2) {
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5));
let cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
let cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);

return Vector2.clamp(position, halfScreen, cameraMax);
}
Expand Down

0 comments on commit 14b70b3

Please sign in to comment.