Skip to content

Commit

Permalink
bug with bounds fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jjppof committed Feb 10, 2024
1 parent 0e34ea9 commit 9624444
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions base/GoldenSun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export class GoldenSun {
x: hero_initial_x,
y: hero_initial_y,
});
this.map.change_camera_bounds();

//initializes the controllable hero
const hero_key_name = this.dbs.init_db.hero_key_name;
Expand Down
15 changes: 11 additions & 4 deletions base/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,17 +1414,24 @@ export class Map {
set_map_bounds(tile_x_pos: number, tile_y_pos: number) {
const x = get_px_position(tile_x_pos, this.tile_width);
const y = get_px_position(tile_y_pos, this.tile_height);
let bound_set = false;
for (let i = 0; i < this.bounding_boxes.length; ++i) {
const bounding_box = this.bounding_boxes[i].rect;
if (bounding_box.contains(x, y)) {
this.game.camera.bounds.setTo(bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
this.current_bounding_box_id = this.bounding_boxes[i].id;
bound_set = true;
break;
}
}
if (!bound_set) {
this.change_camera_bounds();
}

/**
* Updates camera bounds to fit current portion of the map.
*/
change_camera_bounds() {
if (this.current_bounding_box_id !== null && this.current_bounding_box_id >= 0) {
const bounding_box = this.bounding_boxes.find(bb => bb.id === this.current_bounding_box_id).rect;
this.game.camera.bounds.setTo(bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
} else {
this.game.camera.setBoundsToWorld();
}
if (this.game.camera.bounds?.width < numbers.GAME_WIDTH) {
Expand Down
1 change: 1 addition & 0 deletions base/tile_events/TeleportEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ export class TeleportEvent extends TileEvent {
},
previous_map_name === next_map_name ? this.data.map.retreat_data : null
);
this.data.map.change_camera_bounds();
this.data.collision.config_collision_groups(this.data.map);
this.data.map.config_all_bodies(this.data.map.collision_layer);
this.data.collision.config_collisions(this.data.map.collision_layer);
Expand Down

0 comments on commit 9624444

Please sign in to comment.