-
Notifications
You must be signed in to change notification settings - Fork 0
/
movanimator.cpp
52 lines (41 loc) · 1.34 KB
/
movanimator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "movanimator.h"
#include <iostream>
MovAnimator::MovAnimator(Movable* obj):Object(obj),moveAnimTime(200),nbFrames(3),walking(false){
movAnimStatus = 0;
moveAnimTimer.start(moveAnimTime,this);
}
MovAnimator::MovAnimator(Movable* obj,int walkTime,int frames,bool walk) : Object(obj),moveAnimTime(walkTime),nbFrames(frames),walking(walk){
movAnimStatus = 0;
moveAnimTimer.start(moveAnimTime,this);
}
//lance l'animation de marche si pas en cours
void MovAnimator::Walk(){
walking = true;
if (!moveAnimTimer.isActive()){
moveAnimTimer.start(moveAnimTime,this);
}
}
void MovAnimator::StopWalk(){
walking = false;
}
bool MovAnimator::isWalking(){
return walking;
}
bool MovAnimator::isStarted(){
return started;
}
void MovAnimator::StartAnimator(){
started = true;
}
//changement frames de l'animation
void MovAnimator::timerEvent(QTimerEvent *){
Object->renderer.spriteCoords = Object->renderer.initText;
moveAnimTimer.stop();
if (walking){//si en train de marcher, changer frame sur la spritesheet et restart timer
movAnimStatus++;
movAnimStatus = movAnimStatus %nbFrames;
Object->renderer.spriteCoords.setX(Object->renderer.spriteCoords.x()+(movAnimStatus/16.0));
Object->renderer.CreateGeometry();
moveAnimTimer.start(moveAnimTime,this);
}
}