1 Star 0 Fork 0

fanbal/GodotStarLineMirrorDraw

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MainScene.cs 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
fanbal 提交于 2024-04-07 10:41 . 添加项目文件。
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();
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanbal/godot-star-line-mirror-draw.git
git@gitee.com:fanbal/godot-star-line-mirror-draw.git
fanbal
godot-star-line-mirror-draw
GodotStarLineMirrorDraw
master

搜索帮助