Update to camera movement
This commit is contained in:
parent
c5aa58c16d
commit
d3fa1a41b0
@ -25,3 +25,4 @@ func _physics_process(delta):
|
||||
# The second parameter of "move_and_slide" is the normal pointing up.
|
||||
# In the case of a 2D platformer, in Godot, upward is negative y, which translates to -1 as a normal.
|
||||
move_and_slide(velocity, Vector2(0, -1))
|
||||
|
||||
|
@ -2,23 +2,56 @@ extends Camera2D
|
||||
|
||||
|
||||
onready var player = get_node("/root/Map1/Player")
|
||||
onready var background_map = get_node("/root/Map1/background")
|
||||
onready var screen_size = self.get_viewport_rect().size
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass
|
||||
calculate_bounds()
|
||||
print(screen_size)
|
||||
|
||||
var once = true
|
||||
var lockedPlayerCamera = false
|
||||
var min_x = 0
|
||||
var min_y = 0
|
||||
var max_x = 0
|
||||
var max_y = 0
|
||||
var max_x_pixel = 0
|
||||
var max_y_pixel = 0
|
||||
|
||||
func calculate_bounds():
|
||||
var used_cells = background_map.get_used_cells()
|
||||
for pos in used_cells:
|
||||
if pos.x < min_x:
|
||||
min_x = int(pos.x)
|
||||
elif pos.x > max_x:
|
||||
max_x = int(pos.x)
|
||||
if pos.y < min_y:
|
||||
min_y = int(pos.y)
|
||||
elif pos.y > max_y:
|
||||
max_y = int(pos.y)
|
||||
print(min_x,"-",max_x, " AND " ,min_y , "-" , max_y)
|
||||
max_x_pixel = (max_x * 32)
|
||||
max_y_pixel = (max_y * 32)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
CameraToPlayer()
|
||||
if once:
|
||||
AnimateMoveCamera(player.position, Vector2(player.position.x - 10,player.position.y - 10), "position", 2)
|
||||
once = false
|
||||
AnimateMoveCamera(player.position, Vector2(player.position.x - 100,player.position.y - 10), "position", 2)
|
||||
pass
|
||||
|
||||
func get_global_pos():
|
||||
return Vector2(position.x, position.y)
|
||||
|
||||
#Move camera to position
|
||||
func MoveCamera(x, y):
|
||||
if x < int(screen_size.x / 2):
|
||||
print("passing")
|
||||
return
|
||||
if y < int(screen_size.y / 2):
|
||||
print("passing")
|
||||
return
|
||||
position.x = x
|
||||
position.y = y
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user