mirror of
https://github.com/JHDev2006/Super-Mario-Bros.-Remastered-Public.git
synced 2025-10-22 15:38:14 +00:00
Attempt to create more accurate initial camera scroll
This commit is contained in:
@@ -21,6 +21,9 @@ static var cam_locked := false
|
|||||||
var scrolling := false
|
var scrolling := false
|
||||||
var cam_direction := 1
|
var cam_direction := 1
|
||||||
|
|
||||||
|
# how far between the center and the edge of the screen before scrolling to the center
|
||||||
|
const SCROLL_DIFFERENCE := 48.0
|
||||||
|
|
||||||
func _exit_tree() -> void:
|
func _exit_tree() -> void:
|
||||||
cam_locked = false
|
cam_locked = false
|
||||||
|
|
||||||
@@ -46,6 +49,16 @@ func handle_camera(delta: float) -> void:
|
|||||||
|
|
||||||
do_limits()
|
do_limits()
|
||||||
camera.global_position = camera_position + camera_offset
|
camera.global_position = camera_position + camera_offset
|
||||||
|
|
||||||
|
# horizontal adjusgments
|
||||||
|
# if the position is matching the camera, start scrolling towards the center
|
||||||
|
if global_position.x >= camera_position.x:
|
||||||
|
position.x = move_toward(position.x,0.0,delta * 30.0)
|
||||||
|
else:
|
||||||
|
# if the camera if behind the middle of the screen, calculate the current difference
|
||||||
|
position.x = max(min(camera_position.x-global_position.x,SCROLL_DIFFERENCE),position.x)
|
||||||
|
|
||||||
|
|
||||||
update_camera_barriers()
|
update_camera_barriers()
|
||||||
|
|
||||||
func update_camera_barriers() -> void:
|
func update_camera_barriers() -> void:
|
||||||
@@ -67,14 +80,7 @@ func handle_horizontal_scrolling(delta: float) -> void:
|
|||||||
if global_position.x >= camera_position.x:
|
if global_position.x >= camera_position.x:
|
||||||
var offset = 0
|
var offset = 0
|
||||||
scrolling = true
|
scrolling = true
|
||||||
if camera_position.x <= global_position.x - 4:
|
|
||||||
offset = camera_position.x - global_position.x + abs(true_velocity.x * delta)
|
|
||||||
camera_position.x = global_position.x + offset
|
camera_position.x = global_position.x + offset
|
||||||
elif global_position.x >= camera_position.x - get_viewport_rect().size.x / 8:
|
|
||||||
if true_velocity.x > 75:
|
|
||||||
camera_position.x += true_velocity.x * delta / 2
|
|
||||||
else:
|
|
||||||
camera_position.x += true_velocity.x * delta
|
|
||||||
|
|
||||||
## LEFT MOVEMENT
|
## LEFT MOVEMENT
|
||||||
elif true_vel_dir == -1 and can_scroll_left and Global.current_level.can_backscroll:
|
elif true_vel_dir == -1 and can_scroll_left and Global.current_level.can_backscroll:
|
||||||
@@ -82,14 +88,7 @@ func handle_horizontal_scrolling(delta: float) -> void:
|
|||||||
if global_position.x <= camera_position.x:
|
if global_position.x <= camera_position.x:
|
||||||
scrolling = true
|
scrolling = true
|
||||||
var offset = 0
|
var offset = 0
|
||||||
if camera_position.x >= global_position.x + 4:
|
|
||||||
offset = camera_position.x - global_position.x - abs(true_velocity.x * delta)
|
|
||||||
camera_position.x = global_position.x + offset
|
camera_position.x = global_position.x + offset
|
||||||
elif global_position.x <= camera_position.x + get_viewport_rect().size.x / 4:
|
|
||||||
if true_velocity.x < -75:
|
|
||||||
camera_position.x += true_velocity.x * delta / 2
|
|
||||||
else:
|
|
||||||
camera_position.x += true_velocity.x * delta
|
|
||||||
|
|
||||||
|
|
||||||
func handle_vertical_scrolling(_delta: float) -> void:
|
func handle_vertical_scrolling(_delta: float) -> void:
|
||||||
|
Reference in New Issue
Block a user