Parcourir la source

Pass scale as an argument to create an object.

Sam Jaffe il y a 6 ans
Parent
commit
1bca220d9b

+ 1 - 1
engine/src/serial.cxx

@@ -59,7 +59,7 @@ namespace engine {
     identity<graphics::material> mat = to_material(json["material"], mgr);
     auto frame_size = to_vec2(json["frameSize"], make_vector(1.f, 1.f));
     auto origin = to_vec2(json["position"]);
-    return mgr.create_object(mat, origin, frame_size);
+    return mgr.create_object(mat, origin, frame_size, json["scale"].asFloat());
     //    math::dim2::rectangle pos = {to_vec2(json["position"]),
     //                                 mat.actual().size() * frame_size};
     //    return {pos, pos, mat, {{{0, 0}}, frame_size}};

+ 1 - 1
graphics/include/game/graphics/manager.hpp

@@ -29,7 +29,7 @@ namespace graphics {
     identity<texture> get(std::string const & path) const;
 
     object create_object(identity<material> fromMaterial, math::vec2 atPosition,
-                         math::vec2 frameWidth) const;
+                         math::vec2 frameWidth, float scale) const;
     material const & get(identity<material> identity) const;
     texture const & get(identity<texture> identity) const;
 

+ 4 - 3
graphics/src/manager.cxx

@@ -132,8 +132,9 @@ identity<texture> manager::get(std::string const & path) const {
 }
 
 object manager::create_object(identity<material> fromMaterial,
-                              math::vec2 atPosition,
-                              math::vec2 frameWidth) const {
-  math::dim2::rectangle bounds{atPosition, frameWidth * get(fromMaterial).size};
+                              math::vec2 atPosition, math::vec2 frameWidth,
+                              float scale) const {
+  math::dim2::rectangle bounds{atPosition, frameWidth * get(fromMaterial).size *
+                                               (scale ? scale : 1.f)};
   return {bounds, bounds, fromMaterial, {make_vector(0.f, 0.f), frameWidth}};
 }