From f693119c9e102a9b51a1015168ee2a56f2309dd1 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Sun, 5 Jan 2025 16:44:25 +0100 Subject: fixed AnimatorSystem bug so that it takes delta time instead of elapsed time, the Animator api has not been changed --- src/example/rendering_particle.cpp | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'src/example') diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 8be781a..0082b91 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -27,7 +27,7 @@ public: Color color(255, 255, 255, 255); - Asset img {"asset/texture/square.png"}; + Asset img {"asset/spritesheet/pokemon_spritesheet.png"}; Sprite & test_sprite = game_object.add_component( img, @@ -36,21 +36,17 @@ public: .flip = Sprite::FlipSettings {false, false}, .sorting_in_layer = 2, .order_in_layer = 2, - .size = {1, 1}, + .size = {1, 0}, .angle_offset = 0, .position_offset = {0, 1}, .world_space = false, } ); - //auto & emitter = game_object.add_component(test_sprite, ParticleEmitter::Data{}); - Sprite & test_sprite1 = game_object.add_component( - img, - Sprite::Data { - .color = color, - .size = {1, 1}, - .position_offset = {0, -1}, - .world_space = false, + game_object.add_component( + test_sprite, ivec2 {56, 56}, uvec2 {4, 4}, + Animator::Data { + .looping = true, } ); @@ -61,25 +57,6 @@ public: .postion_offset = {1000, 1000}, } ); - - game_object.add_component( - vec2 {1, 1}, vec2 {0, -1}, "ComicSansMS", - Text::Data { - .text_color = Color::RED, - }, - "test TEST" - ); - - game_object - .add_component( - vec2 {1, 1}, vec2 {0, 1}, "Ariel", - Text::Data { - .text_color = Color::BLACK, - }, - "TEST test" - ) - .world_space - = true; } string get_name() const { return "TestScene"; }; -- cgit v1.2.3 From 958475050c80addf584b6a166649c337c68a879f Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 6 Jan 2025 11:26:23 +0100 Subject: make format with small adjustment system --- src/crepe/api/Animator.h | 2 +- src/crepe/system/AnimatorSystem.cpp | 9 +++++---- src/example/rendering_particle.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/example') diff --git a/src/crepe/api/Animator.h b/src/crepe/api/Animator.h index efc2f6e..95539d3 100644 --- a/src/crepe/api/Animator.h +++ b/src/crepe/api/Animator.h @@ -1,7 +1,7 @@ #pragma once -#include "../types.h" #include "../manager/LoopTimerManager.h" +#include "../types.h" #include "Component.h" #include "Sprite.h" diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 1a0cde9..ec9a445 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -34,14 +34,15 @@ void AnimatorSystem::frame_update() { int total_frames = cycle_end - ctx.cycle_start; int curr_cycle_frame = (a.frame - ctx.cycle_start) % total_frames; + if (!ctx.looping && a.frame >= cycle_end) { + a.active = false; + continue; + } + ctx.row = (ctx.cycle_start + curr_cycle_frame) % a.grid_size.x; ctx.col = curr_cycle_frame / a.grid_size.x; a.spritesheet.mask.x = ctx.row * a.spritesheet.mask.w; a.spritesheet.mask.y = ctx.col * a.spritesheet.mask.y; - - if (!ctx.looping && a.frame >= cycle_end) { - a.active = false; - } } } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 0082b91..c28d6a0 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -46,7 +46,7 @@ public: game_object.add_component( test_sprite, ivec2 {56, 56}, uvec2 {4, 4}, Animator::Data { - .looping = true, + .looping = false, } ); -- cgit v1.2.3 From 1880d3bd97524455b72a29603b45de2da8de3f31 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 6 Jan 2025 12:05:51 +0100 Subject: hotfix used a.col which is not permitted --- src/crepe/system/AnimatorSystem.cpp | 13 ++++++------- src/example/rendering_particle.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/example') diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index ec9a445..1a30502 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -25,23 +25,22 @@ void AnimatorSystem::frame_update() { a.elapsed_time += elapsed_time; duration_t frame_duration = 1000ms / ctx.fps; - if (a.elapsed_time <= frame_duration) continue; - - a.elapsed_time = 0ms; - a.frame++; - int cycle_end = (ctx.cycle_end == -1) ? a.grid_size.x : ctx.cycle_end; int total_frames = cycle_end - ctx.cycle_start; int curr_cycle_frame = (a.frame - ctx.cycle_start) % total_frames; + if (a.elapsed_time >= frame_duration) { + a.elapsed_time = 0ms; + a.frame++; + } + if (!ctx.looping && a.frame >= cycle_end) { a.active = false; continue; } ctx.row = (ctx.cycle_start + curr_cycle_frame) % a.grid_size.x; - ctx.col = curr_cycle_frame / a.grid_size.x; - + //ctx.col = curr_cycle_frame / a.grid_size.x; a.spritesheet.mask.x = ctx.row * a.spritesheet.mask.w; a.spritesheet.mask.y = ctx.col * a.spritesheet.mask.y; } diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index c28d6a0..e6b31a7 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -43,13 +43,17 @@ public: } ); - game_object.add_component( + auto & anim = game_object.add_component( test_sprite, ivec2 {56, 56}, uvec2 {4, 4}, Animator::Data { - .looping = false, + .looping = 0, } ); + anim.set_anim(1); + anim.pause(); + anim.next_anim(); + auto & cam = game_object.add_component( ivec2 {1280, 720}, vec2 {5, 5}, Camera::Data { -- cgit v1.2.3