/
physics.cs
48 lines (42 loc) · 1.16 KB
/
physics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Godot;
using System;
public partial class physics : Node2D
{
private SpineSprite celestial_circus;
private float last_x = -1;
private float last_y = -1;
private bool isMouseOver = false;
public override void _Ready()
{
celestial_circus = GetNode<SpineSprite>("celestial-circus");
celestial_circus.GetAnimationState().SetAnimation("wind-idle", true, 0);
celestial_circus.GetAnimationState().SetAnimation("eyeblink-long", true, 1);
celestial_circus.GetAnimationState().SetAnimation("stars", true, 2);
}
public override void _Process(double delta)
{
if (Input.IsMouseButtonPressed(MouseButton.Left) && isMouseOver){
var pos = GetViewport().GetMousePosition();
if(last_x != -1){
var dx = pos.X - last_x;
var dy = pos.Y - last_y;
celestial_circus.GlobalPosition += new Vector2(dx, dy);
celestial_circus.GetSkeleton().PhysicsTranslate(dx * 1 / celestial_circus.Scale.X, dy * 1 / celestial_circus.Scale.Y);
}
last_x = pos.X;
last_y = pos.Y;
}
else{
last_x = -1;
last_y = -1;
}
}
private void _on_area_2d_mouse_entered()
{
isMouseOver = true;
}
private void _on_area_2d_mouse_exited()
{
isMouseOver = false;
}
}