31 lines
904 B
GDScript
31 lines
904 B
GDScript
extends Camera2D
|
|
class_name MoveableCam
|
|
|
|
const CAMSPEED = 10
|
|
#var velo = Vector2.ZERO
|
|
export var camname:String = ""
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
func _physics_process(delta):
|
|
#joymove
|
|
var joy = Vector2(Input.get_joy_axis(0,0),Input.get_joy_axis(0,1))
|
|
if current and (abs(joy.x) > 0.2 or abs(joy.y) > 0.2):
|
|
position += joy * CAMSPEED
|
|
elif current:
|
|
#keybaordmove
|
|
if Input.is_action_pressed("moveup"):
|
|
position.y -= CAMSPEED
|
|
elif Input.is_action_pressed("movedown"):
|
|
position.y += CAMSPEED
|
|
if Input.is_action_pressed("walkleft"):
|
|
position.x -= CAMSPEED
|
|
elif Input.is_action_pressed("walkright"):
|
|
position.x += CAMSPEED
|
|
position.x = clamp(position.x,limit_left,limit_right-get_viewport_rect().size.x)
|
|
position.y = clamp(position.y,limit_top,limit_bottom-get_viewport_rect().size.y)
|
|
|
|
|