aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-21 20:23:19 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-21 20:23:19 +0100
commit9b4fecb5e3996a418502a696b79be92d226f23b1 (patch)
treedcb5282c36349af726b6ad553fb4fc8c386ce038 /src
parent115d6f50152dc018073345800ca90b85846ebaa9 (diff)
rendering particles in at the center point and not in the top left corner.
Diffstat (limited to 'src')
-rw-r--r--src/crepe/facade/SDLContext.cpp4
-rw-r--r--src/example/rendering_particle.cpp6
2 files changed, 5 insertions, 5 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 00523a6..26327b0 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -107,10 +107,10 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const {
SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos,
const double & scale, const Camera & cam) const {
- double adjusted_x = (pos.x - cam.x) * cam.zoom;
- double adjusted_y = (pos.y - cam.y) * cam.zoom;
double adjusted_w = sprite.sprite_rect.w * scale * cam.zoom;
double adjusted_h = sprite.sprite_rect.h * scale * cam.zoom;
+ double adjusted_x = (pos.x - cam.x) * cam.zoom - adjusted_w / 2;
+ double adjusted_y = (pos.y - cam.y) * cam.zoom - adjusted_h / 2;
return SDL_Rect{
.x = static_cast<int>(adjusted_x),
diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp
index 4571afb..dd85689 100644
--- a/src/example/rendering_particle.cpp
+++ b/src/example/rendering_particle.cpp
@@ -23,14 +23,14 @@ using namespace std;
int main(int argc, char * argv[]) {
ComponentManager mgr;
- GameObject game_object = mgr.new_object("", "", Vector2{100, 100}, 0, 0.1);
+ GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 0.1);
RenderSystem sys{mgr};
ParticleSystem psys{mgr};
Color color(255, 255, 255, 255);
Sprite & test_sprite = game_object.add_component<Sprite>(
- make_shared<Texture>("../asset/texture/img.png"), color, FlipSettings{false, false});
+ make_shared<Texture>("asset/texture/img.png"), color, FlipSettings{false, false});
test_sprite.order_in_layer = 5;
auto & test = game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{
@@ -55,7 +55,7 @@ int main(int argc, char * argv[]) {
game_object.add_component<Camera>(Color::WHITE);
game_object
- .add_component<Sprite>(make_shared<Texture>("../asset/texture/img.png"), color,
+ .add_component<Sprite>(make_shared<Texture>("asset/texture/img.png"), color,
FlipSettings{false, false})
.order_in_layer
= 6;