Closed KosnIre closed 8 years ago
In the Tutorial Chapter 12, step 8: the supplied code uses a variable called _halfWidth
_halfWidth
we set the position of our sound to wherever our enemy is (to the bottom of his sprite - where his feet are), and then play the sound. if ((velocity.x != 0 || velocity.y != 0) && touching == FlxObject.NONE) { _sndStep.setPosition(x + _halfWidth, y + height); _sndStep.play(); }
we set the position of our sound to wherever our enemy is (to the bottom of his sprite - where his feet are), and then play the sound.
if ((velocity.x != 0 || velocity.y != 0) && touching == FlxObject.NONE) { _sndStep.setPosition(x + _halfWidth, y + height); _sndStep.play(); }
Using this code results in the following error: source/Enemy.hx:70: characters 28-38 : Unknown identifier : _halfWidth
source/Enemy.hx:70: characters 28-38 : Unknown identifier : _halfWidth
I'm not sure what was intended here, but there are a few options to correct is:
A. FlxSprite has a variable called _halfSize, which is set in resetFrameSize(). I'm not sure if this is the intended use though.
FlxSprite
_halfSize
resetFrameSize()
B. In my Enemy class, I declared a Float called _halfWidth and set it in the constructor function: _halfWidth = width * 0.5;
Enemy
_halfWidth = width * 0.5;
C. In the demo source code, this is calculated each frame when making the call to setPositon: _sndStep.setPosition(x + frameWidth / 2, y + height);
_sndStep.setPosition(x + frameWidth / 2, y + height);
I would like someone to weigh in on the "best approach" here.
Probably A was intended, but _halfWidth is internal and shouldn't be used like that (and has in fact been changed to _halfSize at some point it looks like). C seems like a good fix. 👍
Description
In the Tutorial Chapter 12, step 8: the supplied code uses a variable called
_halfWidth
Using this code results in the following error:
source/Enemy.hx:70: characters 28-38 : Unknown identifier : _halfWidth
Analysis
I'm not sure what was intended here, but there are a few options to correct is:
A.
FlxSprite
has a variable called_halfSize
, which is set inresetFrameSize()
. I'm not sure if this is the intended use though.B. In my
Enemy
class, I declared a Float called_halfWidth
and set it in the constructor function:_halfWidth = width * 0.5;
C. In the demo source code, this is calculated each frame when making the call to setPositon:
_sndStep.setPosition(x + frameWidth / 2, y + height);
I would like someone to weigh in on the "best approach" here.