Skip to content

Commit c12c2bb

Browse files
committed
Fix "Z-pos" value not having effect on some objects, remove duplicate "Layer" option
Removes hardcoded z-pos values some objects used when being drawn. Some objects had both a "Z-pos" and "Layer" option listed, both doing the same, essentially being duplicates. In those cases, "Layer" was removed in favour of "Z-pos". Some objects used to look for a "layer" property in their options and if it wasn't found, they overrode the "Z-pos" property set for `MovingSprite`s. In those cases, reading the "layer" option is now only left for backwards compatibility.
1 parent c8f2697 commit c12c2bb

17 files changed

+34
-57
lines changed

src/object/block.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const float BOUNCY_BRICK_SPEED = 90;
3737
static const float BUMP_ROTATION_ANGLE = 10;
3838

3939
Block::Block(const Vector& pos, const std::string& sprite_file) :
40-
MovingSprite(pos, sprite_file),
40+
MovingSprite(pos, sprite_file, LAYER_OBJECTS + 1),
4141
m_bouncing(false),
4242
m_breaking(false),
4343
m_bounce_dir(0),
@@ -51,7 +51,7 @@ Block::Block(const Vector& pos, const std::string& sprite_file) :
5151
}
5252

5353
Block::Block(const ReaderMapping& mapping, const std::string& sprite_file) :
54-
MovingSprite(mapping, sprite_file),
54+
MovingSprite(mapping, sprite_file, LAYER_OBJECTS + 1),
5555
m_bouncing(false),
5656
m_breaking(false),
5757
m_bounce_dir(0),
@@ -149,12 +149,6 @@ Block::update(float dt_sec)
149149
}
150150
}
151151

152-
void
153-
Block::draw(DrawingContext& context)
154-
{
155-
m_sprite->draw(context.color(), get_pos(), LAYER_OBJECTS+1, m_flip);
156-
}
157-
158152
void
159153
Block::start_bounce(GameObject* hitter)
160154
{

src/object/block.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ class Block : public MovingSprite
3434

3535
virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override;
3636
virtual void update(float dt_sec) override;
37-
virtual void draw(DrawingContext& context) override;
3837

3938
virtual void on_flip(float height) override;
4039

41-
virtual int get_layer() const override { return LAYER_OBJECTS + 1; }
42-
4340
void start_bounce(GameObject* hitter);
4441

4542
protected:

src/object/candle.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Candle::Candle(const ReaderMapping& mapping) :
3939
mapping.get("flicker", flicker, true);
4040
std::vector<float> vColor;
4141
if (!mapping.get("color", vColor)) vColor = {1.0f, 1.0f, 1.0f};
42-
mapping.get("layer", m_layer, 0);
42+
mapping.get("layer", m_layer); // Backwards compatibility
4343

4444
// Change the light color if defined.
4545
if (vColor.size() >= 3) {
@@ -75,9 +75,8 @@ Candle::get_settings()
7575
result.add_bool(_("Burning"), &burning, "burning", true);
7676
result.add_bool(_("Flicker"), &flicker, "flicker", true);
7777
result.add_color(_("Color"), &lightcolor, "color", Color::WHITE);
78-
result.add_int(_("Layer"), &m_layer, "layer", 0);
7978

80-
result.reorder({"burning", "flicker", "name", "sprite", "color", "layer", "x", "y"});
79+
result.reorder({"burning", "flicker", "name", "sprite", "color", "z-pos", "x", "y"});
8180

8281
return result;
8382
}

src/object/conveyor_belt.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
#include "math/util.hpp"
2727
#include "util/reader_mapping.hpp"
2828

29-
ConveyorBelt::ConveyorBelt(const ReaderMapping &reader) :
30-
MovingSprite(reader, "images/objects/conveyor_belt/conveyor.sprite"),
29+
ConveyorBelt::ConveyorBelt(const ReaderMapping& reader) :
30+
MovingSprite(reader, "images/objects/conveyor_belt/conveyor.sprite", LAYER_TILES),
3131
m_running(true),
3232
m_dir(Direction::LEFT),
3333
m_length(1),
@@ -110,9 +110,7 @@ ConveyorBelt::draw(DrawingContext &context)
110110
for (int i = 0; i < m_length; i++)
111111
{
112112
m_sprite->set_frame(frame_index);
113-
Vector pos = get_pos();
114-
pos.x += static_cast<float>(i) * 32.0f;
115-
m_sprite->draw(context.color(), pos, get_layer());
113+
m_sprite->draw(context.color(), get_pos() + Vector(static_cast<float>(i) * 32.f, 0.f), m_layer);
116114
}
117115
}
118116

src/object/conveyor_belt.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class ConveyorBelt final : public MovingSprite
5151
virtual void update(float dt_sec) override;
5252
virtual void draw(DrawingContext& context) override;
5353

54-
virtual int get_layer() const override { return LAYER_TILES; }
55-
5654
virtual void after_editor_set() override;
5755

5856
/** @name Scriptable Methods */

src/object/lit_object.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "util/reader_mapping.hpp"
2626

2727
LitObject::LitObject(const ReaderMapping& reader) :
28-
MovingSprite(reader, "images/objects/lightflower/lightflower1.sprite"),
28+
MovingSprite(reader, "images/objects/lightflower/lightflower1.sprite", LAYER_TILES),
2929
m_light_offset(-6.f, -17.f),
3030
m_light_sprite_name("images/objects/lightflower/light/glow_light.sprite"),
3131
m_sprite_action("default"),
@@ -36,7 +36,7 @@ LitObject::LitObject(const ReaderMapping& reader) :
3636
reader.get("light-offset-y", m_light_offset.y);
3737

3838
reader.get("light-sprite", m_light_sprite_name);
39-
reader.get("layer", m_layer, 0);
39+
reader.get("layer", m_layer); // Backwards compatibility
4040

4141
reader.get("action", m_sprite_action);
4242
reader.get("light-action", m_light_sprite_action);
@@ -68,7 +68,6 @@ LitObject::get_settings()
6868
ObjectSettings result = MovingSprite::get_settings();
6969

7070
result.add_sprite(_("Light sprite"), &m_light_sprite_name, "light-sprite", "images/objects/lightflower/light/glow_light.sprite");
71-
result.add_int(_("Layer"), &m_layer, "layer", 0);
7271

7372
result.add_text(_("Sprite starting action"), &m_sprite_action, "action", "default");
7473
result.add_text(_("Light sprite starting action"), &m_light_sprite_action, "light-action", "default");

src/object/lit_object.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ class LitObject final : public MovingSprite
5050
virtual ObjectSettings get_settings() override;
5151
virtual void after_editor_set() override;
5252

53-
virtual int get_layer() const override { return m_layer; }
54-
5553
virtual void on_flip(float height) override;
5654

5755
/**

src/object/moving_sprite.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class MovingSprite : public MovingObject
6363
virtual void after_editor_set() override;
6464
virtual void on_type_change(int old_type) override;
6565

66-
virtual int get_layer() const override { return m_layer; }
66+
int get_layer() const override { return m_layer; }
6767

6868
bool has_found_sprite() const { return m_sprite_found; }
6969
const std::string& get_sprite_name() const { return m_sprite_name; }

src/object/particlesystem_interactive.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "object/particlesystem_interactive.hpp"
1818

1919
#include "collision/collision.hpp"
20-
#include "editor/editor.hpp"
2120
#include "math/aatriangle.hpp"
2221
#include "object/tilemap.hpp"
2322
#include "supertux/globals.hpp"
@@ -36,19 +35,13 @@ ParticleSystem_Interactive::ParticleSystem_Interactive() :
3635
{
3736
virtual_width = static_cast<float>(SCREEN_WIDTH);
3837
virtual_height = static_cast<float>(SCREEN_HEIGHT);
39-
if (!Editor::is_active()) {
40-
z_pos = 0;
41-
}
4238
}
4339

4440
ParticleSystem_Interactive::ParticleSystem_Interactive(const ReaderMapping& mapping) :
4541
ParticleSystem(mapping)
4642
{
4743
virtual_width = static_cast<float>(SCREEN_WIDTH);
4844
virtual_height = static_cast<float>(SCREEN_HEIGHT);
49-
if (!Editor::is_active()) {
50-
z_pos = 0;
51-
}
5245
}
5346

5447
ParticleSystem_Interactive::~ParticleSystem_Interactive()

src/object/rain_particle_system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void RainParticleSystem::draw(DrawingContext& context)
302302
context.set_translation(Vector(0, 0));
303303
context.color().draw_filled_rect(context.get_rect(),
304304
Color(0.3f, 0.38f, 0.4f, opacity),
305-
199); // TODO: Change the hardcoded layer value with the rain's layer
305+
z_pos);
306306
context.pop_transform();
307307
}
308308

0 commit comments

Comments
 (0)