From 195f7770c42aa1ed1052725dde26699d2ecc689f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 20:46:32 +0200 Subject: implement get_component for scripts --- src/example/script.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/example') diff --git a/src/example/script.cpp b/src/example/script.cpp index d0cc121..43f1c22 100644 --- a/src/example/script.cpp +++ b/src/example/script.cpp @@ -11,13 +11,17 @@ #include #include #include +#include using namespace crepe; using namespace crepe::api; using namespace std; class MyScript : public Script { - void update() { dbg_log("MY SCRIPT UPDATE"); } + void update() { + Transform & test = get_component(); + dbg_logf("Transform(%.2f, %.2f)", test.position.x, test.position.y); + } }; int main() { @@ -25,6 +29,11 @@ int main() { cfg.log.level = util::LogLevel::TRACE; auto obj = GameObject(0, "name", "tag", 0); + Point point = { + .x = 1.2, + .y = 3.4, + }; + obj.add_component(point, 0, 0); obj.add_component().set_script(); auto & sys = ScriptSystem::get_instance(); -- cgit v1.2.3