mirror of
https://github.com/godotengine/gdnative-demos.git
synced 2026-01-03 14:09:44 +03:00
Improve outdated README files and improve simple C++ demo
This commit is contained in:
30
cpp/simple/README.md
Normal file
30
cpp/simple/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Simple GDNative C++ demo
|
||||
|
||||
This is a small example using C++ to create a GDNative script
|
||||
that just showcases some very simple bare bones calls.
|
||||
|
||||
Language: C++
|
||||
|
||||
Renderer: GLES 2
|
||||
|
||||
Dependencies:
|
||||
* You need [godot-cpp](https://github.com/godotengine/godot-cpp),
|
||||
this is now a Git submodule of this repo.
|
||||
* `clang`, `gcc`, or any decent C++ compiler that's C++14 compatible.
|
||||
|
||||
## Compiling
|
||||
|
||||
You can use SCons to compile the library:
|
||||
|
||||
```
|
||||
scons platform=PLATFORM
|
||||
```
|
||||
|
||||
Where PLATFORM is: `windows`, `linux`, or `osx`.
|
||||
|
||||
This creates the file `libsimple` in the respective
|
||||
subfolders in the `project/gdnative` directory.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
@@ -1,18 +0,0 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
radiance_size = 4
|
||||
sky_top_color = Color( 0.0470588, 0.454902, 0.976471, 1 )
|
||||
sky_horizon_color = Color( 0.556863, 0.823529, 0.909804, 1 )
|
||||
sky_curve = 0.25
|
||||
ground_bottom_color = Color( 0.101961, 0.145098, 0.188235, 1 )
|
||||
ground_horizon_color = Color( 0.482353, 0.788235, 0.952941, 1 )
|
||||
ground_curve = 0.01
|
||||
sun_energy = 16.0
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
fog_height_min = 0.0
|
||||
fog_height_max = 100.0
|
||||
ssao_quality = 0
|
||||
@@ -24,7 +24,7 @@ __meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
[node name="SimpleSprite" type="Sprite" parent="."]
|
||||
position = Vector2( 100, 100 )
|
||||
texture = ExtResource( 2 )
|
||||
script = ExtResource( 3 )
|
||||
|
||||
@@ -14,11 +14,14 @@ _global_script_class_icons={
|
||||
|
||||
[application]
|
||||
|
||||
config/name="New Game Project"
|
||||
config/name="Simple GDNative C++ demo"
|
||||
run/main_scene="res://main.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/driver/fallback_to_gles2=true
|
||||
environment/default_environment="res://default_env.tres"
|
||||
quality/driver/driver_name="GLES2"
|
||||
quality/intended_usage/framebuffer_allocation=0
|
||||
quality/intended_usage/framebuffer_allocation.mobile=0
|
||||
vram_compression/import_etc=true
|
||||
vram_compression/import_etc2=false
|
||||
|
||||
BIN
cpp/simple/screenshots/screenshot.png
Normal file
BIN
cpp/simple/screenshots/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -19,16 +19,17 @@ void SimpleSprite::_register_methods() {
|
||||
}
|
||||
|
||||
// `_init` doesn't need to be registered in `_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!");
|
||||
}
|
||||
|
||||
void SimpleSprite::_process(double delta) {
|
||||
void SimpleSprite::_process(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");
|
||||
|
||||
set_position(get_position() + input_dir.normalized() * delta * 300);
|
||||
set_position(get_position() + input_dir.normalized() * p_delta * 300);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#ifndef SIMPLE_H
|
||||
#define SIMPLE_H
|
||||
|
||||
#include <Godot.hpp>
|
||||
|
||||
#include <Reference.hpp>
|
||||
@@ -24,5 +27,7 @@ public:
|
||||
|
||||
void _init();
|
||||
|
||||
void _process(double delta);
|
||||
void _process(double p_delta);
|
||||
};
|
||||
|
||||
#endif // SIMPLE_H
|
||||
|
||||
Reference in New Issue
Block a user