Created
August 30, 2018 15:56
-
-
Save groud/518598d2682725535c99feb0dfa77e9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Sprite | |
var area | |
var camera | |
var anchor | |
func input(viewport, event, shape_idx): | |
if event is InputEventMouseButton and not event.pressed: | |
printt("Before affecting zoom:", anchor.global_position, anchor.position) | |
if event.button_index == 5: | |
# zoom out | |
camera.zoom *= 1.2 | |
anchor.position = camera.get_canvas_transform().xform($"../Target".position) | |
elif event.button_index == 4: | |
# zoom in | |
camera.zoom *= 0.833 | |
anchor.position = camera.get_canvas_transform().xform($"../Target".position) | |
# anchor.global_position *= 0.833 | |
func _enter_tree(): | |
# Use size of background texture to calculate collision shape | |
var size = get_texture().get_size() | |
area = Area2D.new() | |
var shape = RectangleShape2D.new() | |
var sid = area.create_shape_owner(area) | |
# Move origin of Area2D to center of Sprite | |
var transform = area.shape_owner_get_transform(sid) | |
transform.origin = size / 2 | |
area.shape_owner_set_transform(sid, transform) | |
# Set extents of RectangleShape2D to cover entire Sprite | |
shape.set_extents(size / 2) | |
area.shape_owner_add_shape(sid, shape) | |
add_child(area) | |
camera = $"../camera" | |
anchor = $"../dialog_layer/anchor_for_moving" # Because Control doesn't have `global_position` | |
func _ready(): | |
area.connect("input_event", self, "input") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment