Drag and drop on one letter
This commit is contained in:
6
.idea/.idea.lettergodot/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.lettergodot/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,3 +1,3 @@
|
||||
source_md5="f5d06c14307c82e2f17c30c2cada4aaf"
|
||||
dest_md5="9046431784da2a704a005a1a9736bce9"
|
||||
source_md5="c7f8f0dddc88b7eec79299922eb21792"
|
||||
dest_md5="2cc9861875e395760ada61eaac328f47"
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,3 @@
|
||||
source_md5="787f1a6bf5f4d4724674893cc1b67f2a"
|
||||
dest_md5="1adb25cbd54eabb69378b280ed8ab3a7"
|
||||
source_md5="afd95580a7ff7cb33694cbe8e207bcf4"
|
||||
dest_md5="f2ef13e899c147525e9cbcd70c3df780"
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
{"res://startup.cs":{"modified_time":"1669549042","class":{"namespace":"","class_name":"startup","nested":false}},"res://MainBoard.cs":{"modified_time":"1669562782","class":{"namespace":"","class_name":"MainBoard","nested":false}},"res://Letterbox.cs":{"modified_time":"1669573463","class":{"namespace":"","class_name":"Letterbox","nested":false}},"res://Letter.cs":{"modified_time":"1669573955","class":{"namespace":"","class_name":"Letter","nested":false}}}
|
||||
{"res://startup.cs":{"modified_time":"1669549042","class":{"namespace":"","class_name":"startup","nested":false}},"res://MainBoard.cs":{"modified_time":"1669562782","class":{"namespace":"","class_name":"MainBoard","nested":false}},"res://Letterbox.cs":{"modified_time":"1669573463","class":{"namespace":"","class_name":"Letterbox","nested":false}},"res://Letter.cs":{"modified_time":"1669573955","class":{"namespace":"","class_name":"Letter","nested":false}},"res://DragAndDrop.cs":{"modified_time":"1670104203","class":{"namespace":"","class_name":"DragAndDrop","nested":false}}}
|
||||
@@ -1 +1 @@
|
||||
{"res://startup.cs":{"modified_time":"1669549042","class":{"namespace":"","class_name":"startup","nested":false}},"res://MainBoard.cs":{"modified_time":"1669562782","class":{"namespace":"","class_name":"MainBoard","nested":false}},"res://Letterbox.cs":{"modified_time":"1669573463","class":{"namespace":"","class_name":"Letterbox","nested":false}},"res://Letter.cs":{"modified_time":"1669573955","class":{"namespace":"","class_name":"Letter","nested":false}}}
|
||||
{"res://startup.cs":{"modified_time":"1669549042","class":{"namespace":"","class_name":"startup","nested":false}},"res://MainBoard.cs":{"modified_time":"1669562782","class":{"namespace":"","class_name":"MainBoard","nested":false}},"res://Letterbox.cs":{"modified_time":"1669573463","class":{"namespace":"","class_name":"Letterbox","nested":false}},"res://Letter.cs":{"modified_time":"1669573955","class":{"namespace":"","class_name":"Letter","nested":false}},"res://DragAndDrop.cs":{"modified_time":"1670104203","class":{"namespace":"","class_name":"DragAndDrop","nested":false}}}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
194d9691006bfa5b5c27e03b194ebedf65c8d004
|
||||
db9b024c33a259610ef0df1da5a4f7037f4aadf2
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
16695434926457618
|
||||
16700998578786145
|
||||
95
DragAndDrop.cs
Normal file
95
DragAndDrop.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public class DragAndDrop : KinematicBody2D
|
||||
{
|
||||
|
||||
/*
|
||||
Convert this code to C#
|
||||
|
||||
extends KinematicBody2D
|
||||
|
||||
var dragging = false
|
||||
|
||||
signal dragsignal;
|
||||
|
||||
func _ready():
|
||||
connect("dragsignal",self,"_set_drag_pc")
|
||||
|
||||
|
||||
func _process(delta):
|
||||
if dragging:
|
||||
var mousepos = get_viewport().get_mouse_position()
|
||||
self.position = Vector2(mousepos.x, mousepos.y)
|
||||
|
||||
|
||||
|
||||
func _set_drag_pc():
|
||||
dragging=!dragging
|
||||
|
||||
|
||||
func _on_KinematicBody2D_input_event(viewport, event, shape_idx):
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.pressed:
|
||||
emit_signal("dragsignal")
|
||||
elif event.button_index == BUTTON_LEFT and !event.pressed:
|
||||
emit_signal("dragsignal")
|
||||
elif event is InputEventScreenTouch:
|
||||
if event.pressed and event.get_index() == 0:
|
||||
self.position = event.get_position()
|
||||
|
||||
|
||||
*/
|
||||
|
||||
private bool dragging = false;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Connect("dragsignal", this, "DragSignalImplemenmtation");
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(float delta)
|
||||
{
|
||||
if (dragging)
|
||||
{
|
||||
var mousepos = GetViewport().GetMousePosition();
|
||||
Position = new Vector2(mousepos.x, mousepos.y);
|
||||
}
|
||||
}
|
||||
|
||||
[Signal]
|
||||
public delegate void dragsignal();
|
||||
|
||||
private void DragSignalImplemenmtation()
|
||||
{
|
||||
dragging = !dragging;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton)
|
||||
{
|
||||
var eventMouseButton = (InputEventMouseButton)@event;
|
||||
if (eventMouseButton.ButtonIndex == (int)ButtonList.Left && eventMouseButton.Pressed)
|
||||
{
|
||||
EmitSignal("dragsignal");
|
||||
}
|
||||
else if (eventMouseButton.ButtonIndex == (int)ButtonList.Left && !eventMouseButton.Pressed)
|
||||
{
|
||||
EmitSignal("dragsignal");
|
||||
}
|
||||
}
|
||||
else if (@event is InputEventScreenTouch)
|
||||
{
|
||||
var eventScreenTouch = (InputEventScreenTouch)@event;
|
||||
if (eventScreenTouch.Pressed && eventScreenTouch.Index == 0)
|
||||
{
|
||||
Position = eventScreenTouch.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 22 KiB |
BIN
lettertileup.png
BIN
lettertileup.png
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 8.3 KiB |
28
main.tscn
28
main.tscn
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=8 format=2]
|
||||
[gd_scene load_steps=10 format=2]
|
||||
|
||||
[ext_resource path="res://main.tres" type="TileSet" id=1]
|
||||
[ext_resource path="res://MainBoard.cs" type="Script" id=2]
|
||||
[ext_resource path="res://lettertileup.png" type="Texture" id=3]
|
||||
[ext_resource path="res://Letterbox.cs" type="Script" id=4]
|
||||
[ext_resource path="res://Letter.cs" type="Script" id=5]
|
||||
[ext_resource path="res://DragAndDrop.cs" type="Script" id=6]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=2]
|
||||
|
||||
@@ -16,6 +17,9 @@ animations = [ {
|
||||
"speed": 5.0
|
||||
} ]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id=3]
|
||||
extents = Vector2( 49, 53.5 )
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
material = SubResource( 2 )
|
||||
|
||||
@@ -30,12 +34,6 @@ script = ExtResource( 2 )
|
||||
position = Vector2( 1, 4 )
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="Letter1" type="AnimatedSprite" parent="Letterbox"]
|
||||
position = Vector2( 263, 1335 )
|
||||
scale = Vector2( 1.5, 1.5 )
|
||||
frames = SubResource( 1 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="Letter2" type="AnimatedSprite" parent="Letterbox"]
|
||||
position = Vector2( 360, 1335 )
|
||||
scale = Vector2( 1.5, 1.5 )
|
||||
@@ -71,3 +69,19 @@ position = Vector2( 845, 1335 )
|
||||
scale = Vector2( 1.5, 1.5 )
|
||||
frames = SubResource( 1 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="KinematicBody2D" type="KinematicBody2D" parent="Letterbox"]
|
||||
position = Vector2( 263, 1335 )
|
||||
scale = Vector2( 1.5, 1.5 )
|
||||
input_pickable = true
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="Letter1" type="AnimatedSprite" parent="Letterbox/KinematicBody2D"]
|
||||
frames = SubResource( 1 )
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Letterbox/KinematicBody2D"]
|
||||
position = Vector2( 262, 1333.5 )
|
||||
shape = SubResource( 3 )
|
||||
|
||||
[connection signal="input_event" from="Letterbox/KinematicBody2D" to="Letterbox/KinematicBody2D" method="_on_KinematicBody2D_input_event"]
|
||||
|
||||
Reference in New Issue
Block a user