@@ -6,31 +6,30 @@ using namespace std;
66
77// constructor, initialises default sprite size and default animation speed
88AnimatedSpriteComponent::AnimatedSpriteComponent (Entity* p, Vector2f size) : Component(p), _size(size), _rotation(0 ) {
9- // total accumulated time, used to tell when to switch to the next frame
10- _totalTime = 0 .0f ;
11- // the texture rect's width and height
12- _currentFrame.width = _size.x ;
13- _currentFrame.height = _size.y ;
14- // current frame, default 0, 0
15- _currentImage = Vector2u (0 , 0 );
16- // default animation speed
17- _frameTime = 0 .2f ;
18- // this boolean is used to decide whether to flip the sprite or not
19- _facingRight = true ;
20- // set this to the padding between rows in the spritesheet!!
21- // all online spritesheet packers seem to add padding for some reason
22- _spriteSheetPadding = 0 ;
23- _currentRow = 0 ;
24- _hurt = false ;
25- _hurtTimer = 1 .0f ;
26- _numOfFrames = 1 ;
27- _done = false ;
28- _frameDecline = _numOfFrames;
29- // set origin
30- auto origin = _size / 2 .f ;
31- origin.x = floor (origin.x );
32- origin.y = floor (origin.y );
33- _sprite.setOrigin (origin);
9+ // total accumulated time, used to tell when to switch to the next frame
10+ _totalTime = 0 .0f ;
11+ // the texture rect's width and height
12+ _currentFrame.width = _size.x ;
13+ _currentFrame.height = _size.y ;
14+ // current frame, default 0, 0
15+ _currentImage = Vector2u (0 , 0 );
16+ // default animation speed
17+ _frameTime = 0 .2f ;
18+ // this boolean is used to decide whether to flip the sprite or not
19+ _facingRight = true ;
20+ // set this to the padding between rows in the spritesheet!!
21+ // all online spritesheet packers seem to add padding for some reason
22+ _spriteSheetPadding = 0 ;
23+ _currentRow = 0 ;
24+ _hurt = false ;
25+ _hurtTimer = 1 .0f ;
26+ _numOfFrames = 1 ;
27+ _done = false ;
28+ // set origin
29+ auto origin = _size / 2 .f ;
30+ origin.x = floor (origin.x );
31+ origin.y = floor (origin.y );
32+ _sprite.setOrigin (origin);
3433}
3534
3635void AnimatedSpriteComponent::update (double dt) {
@@ -54,18 +53,8 @@ void AnimatedSpriteComponent::update(double dt) {
5453 // unlock
5554 _locked = false ;
5655 _done = true ;
57- if (!_stalled){
5856 // restart from the first frame
5957 _currentImage.x = 0 ;
60- }
61- // else{
62- // if(_frameDecline ==_numOfFrames-1){
63- // _currentImage.x= _numOfFrames-_frameDecline--;
64- // _currentImage.x=_numOfFrames-_frameDecline--;
65- // }
66-
67- // }
68-
6958 }
7059
7160 }
@@ -81,7 +70,7 @@ void AnimatedSpriteComponent::update(double dt) {
8170 _currentFrame.left = (_currentImage.x + 1 ) * abs (_currentFrame.width );
8271 _currentFrame.width = -abs (_currentFrame.width );
8372 }
84-
73+
8574 // calculate spritesheet y coordinate, don't forget padding
8675 _currentFrame.top = _currentImage.y * _size.y + _spriteSheetPadding;
8776
@@ -122,15 +111,6 @@ void AnimatedSpriteComponent::lockInAnimation(unsigned int row) {
122111 _locked = true ;
123112}
124113
125- void AnimatedSpriteComponent::stallAnimation (int row){
126- _stalled = true ;
127- if (isDone ()){
128- _currentImage.y = row;
129- _currentImage.x = _numOfFrames-1 ;
130- }
131-
132- }
133-
134114// sets the spritesheet, using the passed reference to a spritesheet
135115void AnimatedSpriteComponent::setSpritesheet (const sf::Texture& sh) {
136116 _spritesheet = sh;
@@ -153,7 +133,7 @@ void AnimatedSpriteComponent::setNumberOfFrames(int num) {
153133void AnimatedSpriteComponent::setCurrentRow (int r) {
154134 // if changing to a new animation
155135 if (_currentRow != r) {
156- _currentRow = r;
136+ _currentRow = r;
157137 // reset to first frame
158138 _currentImage.x = 0 ;
159139 }
0 commit comments