base level camera
This commit is contained in:
parent
807902b7fc
commit
0aebf6fa9b
8 changed files with 126 additions and 3 deletions
30
scripts/blocks_programm/base_level.gd
Normal file
30
scripts/blocks_programm/base_level.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Node2D
|
||||
const UP = 4
|
||||
const DOWN = 1
|
||||
|
||||
var poss = Vector2()
|
||||
var cam = Vector2()
|
||||
var pressed = false
|
||||
|
||||
|
||||
@onready var camera: Camera2D = $Camera2D
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if Input.is_action_just_released("wheel_up") and camera.zoom.x < UP:
|
||||
camera.zoom.x += 0.1
|
||||
camera.zoom.y += 0.1
|
||||
if Input.is_action_just_released("wheel_down")and camera.zoom.x > DOWN:
|
||||
camera.zoom.x -= 0.1
|
||||
camera.zoom.y -= 0.1
|
||||
if pressed:
|
||||
camera.position = (cam + poss) - (camera.get_local_mouse_position())
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action("mouse_press"):
|
||||
if event.is_pressed():
|
||||
poss = camera.get_local_mouse_position()
|
||||
cam = camera.position
|
||||
pressed = true
|
||||
else:
|
||||
pressed = false
|
Loading…
Add table
Add a link
Reference in a new issue