修复切换场景未移除问题
This commit is contained in:
@@ -15,13 +15,13 @@ class MainScene extends Scene {
|
||||
bg.addComponent(new PlayerController());
|
||||
bg.addComponent(new Mover());
|
||||
bg.addComponent(new BoxCollider());
|
||||
bg.position = new Vector2(Math.random() * 200, Math.random() * 200);
|
||||
bg.position = new Vector2(30, 30);
|
||||
|
||||
for (let i = 0; i < 100; i++) {
|
||||
for (let i = 0; i < 1; i++) {
|
||||
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
|
||||
let player2 = this.createEntity("player2");
|
||||
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
|
||||
player2.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i);
|
||||
player2.position = new Vector2(10, 10);
|
||||
player2.addComponent(new BoxCollider());
|
||||
}
|
||||
|
||||
@@ -63,24 +63,24 @@ class MainScene extends Scene {
|
||||
public dijkstraTest() {
|
||||
let graph = new WeightedGridGraph(20, 20);
|
||||
|
||||
graph.weightedNodes.push(new Point(3, 3));
|
||||
graph.weightedNodes.push(new Point(3, 4));
|
||||
graph.weightedNodes.push(new Point(4, 3));
|
||||
graph.weightedNodes.push(new Point(4, 4));
|
||||
graph.weightedNodes.push(new Vector2(3, 3));
|
||||
graph.weightedNodes.push(new Vector2(3, 4));
|
||||
graph.weightedNodes.push(new Vector2(4, 3));
|
||||
graph.weightedNodes.push(new Vector2(4, 4));
|
||||
|
||||
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
||||
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
|
||||
console.log(path);
|
||||
}
|
||||
|
||||
public astarTest() {
|
||||
let graph = new AstarGridGraph(20, 20);
|
||||
|
||||
graph.weightedNodes.push(new Point(3, 3));
|
||||
graph.weightedNodes.push(new Point(3, 4));
|
||||
graph.weightedNodes.push(new Point(4, 3));
|
||||
graph.weightedNodes.push(new Point(4, 4));
|
||||
graph.weightedNodes.push(new Vector2(3, 3));
|
||||
graph.weightedNodes.push(new Vector2(3, 4));
|
||||
graph.weightedNodes.push(new Vector2(4, 3));
|
||||
graph.weightedNodes.push(new Vector2(4, 4));
|
||||
|
||||
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
||||
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
|
||||
console.log(path);
|
||||
}
|
||||
}
|
||||
@@ -34,23 +34,23 @@ class PlayerController extends Component {
|
||||
return;
|
||||
|
||||
if (this.down){
|
||||
let camera = SceneManager.scene.camera;
|
||||
let moveLeft: number = 0;
|
||||
let moveRight: number = 0;
|
||||
let speed = 200;
|
||||
let worldPos = Input.touchPosition;
|
||||
if (worldPos.x < this.spriteRenderer.x){
|
||||
moveLeft = -1;
|
||||
} else if(worldPos.x > this.spriteRenderer.x){
|
||||
moveLeft = 1;
|
||||
}
|
||||
// let camera = SceneManager.scene.camera;
|
||||
// let moveLeft: number = 0;
|
||||
// let moveRight: number = 0;
|
||||
// let speed = 100;
|
||||
// let worldPos = Input.touchPosition;
|
||||
// if (worldPos.x < this.spriteRenderer.x){
|
||||
// moveLeft = -1;
|
||||
// } else if(worldPos.x > this.spriteRenderer.x){
|
||||
// moveLeft = 1;
|
||||
// }
|
||||
|
||||
if (worldPos.y < this.spriteRenderer.y){
|
||||
moveRight = -1;
|
||||
} else if(worldPos.y > this.spriteRenderer.y){
|
||||
moveRight = 1;
|
||||
}
|
||||
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
|
||||
// if (worldPos.y < this.spriteRenderer.y){
|
||||
// moveRight = -1;
|
||||
// } else if(worldPos.y > this.spriteRenderer.y){
|
||||
// moveRight = 1;
|
||||
// }
|
||||
this.mover.move(new Vector2(-1, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user