mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-03 14:09:44 +03:00
Move input and random number generator to headers and _ready()
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
#include "Simple.hpp"
|
||||
|
||||
#include "Input.hpp"
|
||||
|
||||
void Simple::_register_methods() {
|
||||
godot::register_method("get_data", &Simple::get_data);
|
||||
}
|
||||
@@ -22,14 +20,14 @@ void SimpleSprite::_register_methods() {
|
||||
// `_init` is always required, if you exclude it then Godot will crash.
|
||||
void SimpleSprite::_init() {
|
||||
godot::Godot::print("A SimpleSprite was initialized in GDNative!");
|
||||
_input = godot::Input::get_singleton();
|
||||
}
|
||||
|
||||
void SimpleSprite::_process(const double p_delta) {
|
||||
godot::Input *input = godot::Input::get_singleton();
|
||||
godot::Vector2 input_dir(0, 0);
|
||||
|
||||
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");
|
||||
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() * (real_t)p_delta * 300);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <Godot.hpp>
|
||||
|
||||
#include <Input.hpp>
|
||||
#include <Reference.hpp>
|
||||
#include <Sprite.hpp>
|
||||
|
||||
@@ -22,6 +23,8 @@ public:
|
||||
class SimpleSprite : public godot::Sprite {
|
||||
GODOT_CLASS(SimpleSprite, godot::Sprite)
|
||||
|
||||
godot::Input *_input;
|
||||
|
||||
public:
|
||||
static void _register_methods();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user