代码拉取完成,页面将自动刷新
using Godot;
using System;
public partial class MainScene : Node2D
{
private RectCoordinate _rectCoordinate;
private HSlider _slider;
private Vector2 _dragStartPoint;
private bool _leftButtonPressedState;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_slider = GetNode<HSlider>(@"ResizeSlider");
_rectCoordinate = GetNode<RectCoordinate>(@"RectCoordinate");
_slider.ValueChanged += _slider_ValueChanged;
_slider.Value = _rectCoordinate.Interval;
}
private void _slider_ValueChanged(double value)
{
_rectCoordinate.Interval = (float)value;
_rectCoordinate.QueueRedraw();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
var currentLeftButtonState = Input.IsMouseButtonPressed(MouseButton.Left);
if (currentLeftButtonState == true && _leftButtonPressedState == false)
{
OnMousePressed();
}
else if (currentLeftButtonState == false && _leftButtonPressedState == true)
{
OnMouseReleased();
}
else if (currentLeftButtonState == true)
{
OnMouseMove();
}
_leftButtonPressedState = currentLeftButtonState;
}
private void OnMousePressed()
{
var viewport = GetViewport();
var mpos = viewport.GetMousePosition();
var opos = _rectCoordinate.Position;
_dragStartPoint = mpos - opos;
}
private void OnMouseReleased()
{
}
private void OnMouseMove()
{
var viewport = GetViewport();
var mpos = viewport.GetMousePosition();
_rectCoordinate.Position = mpos - _dragStartPoint;
_rectCoordinate.QueueRedraw();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。