Skip to content

Commit ecb9350

Browse files
authored
Move dart's sprite action initialisation to the constructor(s) (#2567)
Since the dart's direction is already known at the time of the Dart object being created, there's no reason the sprite action shouldn't be initialised in the constructor. This fixes an oversight from #2554 where the dart's position when spawning from a DartTrap is calculated from the sprite before its proper action is set, resulting in the maths not being correct for three of the four directions. I didn't notice this before since the dart is only spawned off by a few pixels, but it would be a bigger problem for custom dart sprites. Moving the sprite action to the constructor(s) fixes this, since the sprite action is already set properly at the time the dart's position is calculated when being shot out of a DartTrap. EDIT: Alternatively, I could keep the sprite action initialisation in Dart::initialize() and set the action manually in DartTrap::fire() before Dart::initialize() is called. That would fix the problem too. Whichever you think is better.
1 parent 081f81a commit ecb9350

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/badguy/dart.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Dart::Dart(const ReaderMapping& reader) :
3737
SoundManager::current()->preload(DART_SOUND);
3838
SoundManager::current()->preload("sounds/darthit.wav");
3939
SoundManager::current()->preload("sounds/stomp.wav");
40+
41+
set_action("flying", m_dir);
4042
}
4143

4244
Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_, const std::string& sprite) :
@@ -49,6 +51,8 @@ Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_, const std::str
4951
SoundManager::current()->preload(DART_SOUND);
5052
SoundManager::current()->preload("sounds/darthit.wav");
5153
SoundManager::current()->preload("sounds/stomp.wav");
54+
55+
set_action("flying", m_dir);
5256
}
5357

5458
bool
@@ -66,7 +70,6 @@ Dart::initialize()
6670
{
6771
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -::DART_SPEED : m_dir == Direction::RIGHT ? ::DART_SPEED : 0);
6872
m_physic.set_velocity_y(m_dir == Direction::UP ? -::DART_SPEED : m_dir == Direction::DOWN ? ::DART_SPEED : 0);
69-
set_action("flying", m_dir);
7073
}
7174

7275
void

0 commit comments

Comments
 (0)