mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-04 22:10:30 +03:00
Add ability for SimpleSprite to move as intended
This commit is contained in:
9
cpp/simple/project/gdnative/simple_sprite.gdns
Normal file
9
cpp/simple/project/gdnative/simple_sprite.gdns
Normal file
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="NativeScript" load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://gdnative/simple.gdnlib" type="GDNativeLibrary" id=1]
|
||||
|
||||
[resource]
|
||||
|
||||
resource_name = "SimpleSprite"
|
||||
class_name = "SimpleSprite"
|
||||
library = ExtResource( 1 )
|
||||
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://icon.png" type="Texture" id=2]
|
||||
[ext_resource path="res://gdnative/simple_sprite.gdns" type="Script" id=3]
|
||||
|
||||
[node name="Node" type="Node"]
|
||||
script = ExtResource( 1 )
|
||||
@@ -19,8 +20,12 @@ margin_top = 360.0
|
||||
margin_right = 662.0
|
||||
margin_bottom = 374.0
|
||||
align = 1
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 2 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]
|
||||
|
||||
@@ -18,25 +18,17 @@ void SimpleSprite::_register_methods() {
|
||||
godot::register_method("_process", &SimpleSprite::_process);
|
||||
}
|
||||
|
||||
// `_init` doesn't need to be registered in `_register_methods`.
|
||||
void SimpleSprite::_init() {
|
||||
godot::Godot::print("Wheeeeey");
|
||||
godot::Godot::print("A SimpleSprite was initialized in GDNative!");
|
||||
}
|
||||
|
||||
void SimpleSprite::_process(double delta) {
|
||||
godot::Input *input = godot::Input::get_singleton();
|
||||
godot::Vector2 input_dir(0, 0);
|
||||
|
||||
if (godot::Input::get_singleton()->is_action_pressed("ui_right")) {
|
||||
input_dir.x += 1;
|
||||
}
|
||||
if (godot::Input::get_singleton()->is_action_pressed("ui_left")) {
|
||||
input_dir.x -= 1;
|
||||
}
|
||||
if (godot::Input::get_singleton()->is_action_pressed("ui_down")) {
|
||||
input_dir.y += 1;
|
||||
}
|
||||
if (godot::Input::get_singleton()->is_action_pressed("ui_up")) {
|
||||
input_dir.y -= 1;
|
||||
}
|
||||
input_dir.x = input->get_action_strength("ui_right") - input->get_action_strength("ui_left");
|
||||
input_dir.y = input->get_action_strength("ui_down") - input->get_action_strength("ui_up");
|
||||
|
||||
set_position(get_position() + input_dir.normalized() * delta * 300);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user