lesson#29 flip texture option added
This commit is contained in:
parent
57adfea05a
commit
ab9df3a8ff
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 9.5 KiB |
|
@ -11,15 +11,17 @@ struct Animation {
|
||||||
float frameTimeSecs;
|
float frameTimeSecs;
|
||||||
float frameTimeSecsLeft;
|
float frameTimeSecsLeft;
|
||||||
bool isActive;
|
bool isActive;
|
||||||
|
bool flip;
|
||||||
}
|
}
|
||||||
|
|
||||||
this(in Texture2D texture, in int numFrames, in int numRows, in float frameTimeSecs, in int useRow = 1) {
|
this(in Texture2D texture, in int numFrames, in int numRows, in float frameTimeSecs, in int useRow = 1, in bool flip = false) {
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
this.numFrames = numFrames;
|
this.numFrames = numFrames;
|
||||||
this.frameTimeSecs = frameTimeSecs;
|
this.frameTimeSecs = frameTimeSecs;
|
||||||
this.frameTimeSecsLeft = frameTimeSecs;
|
this.frameTimeSecsLeft = frameTimeSecs;
|
||||||
this.currentFrame = 0;
|
this.currentFrame = 0;
|
||||||
this.isActive = true;
|
this.isActive = true;
|
||||||
|
this.flip = flip;
|
||||||
|
|
||||||
// create rectangle frames
|
// create rectangle frames
|
||||||
immutable frameWidth = texture.width / numFrames;
|
immutable frameWidth = texture.width / numFrames;
|
||||||
|
@ -55,8 +57,19 @@ struct Animation {
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(in Vector2 position) {
|
void draw(in Vector2 position) {
|
||||||
|
if (flip) {
|
||||||
|
DrawTextureRec(texture,
|
||||||
|
Rectangle(
|
||||||
|
rectFrames[currentFrame].x,
|
||||||
|
rectFrames[currentFrame].y,
|
||||||
|
-rectFrames[currentFrame].width,
|
||||||
|
rectFrames[currentFrame].height
|
||||||
|
),
|
||||||
|
position, Colors.WHITE);
|
||||||
|
} else {
|
||||||
DrawTextureRec(texture, rectFrames[currentFrame], position, Colors.WHITE);
|
DrawTextureRec(texture, rectFrames[currentFrame], position, Colors.WHITE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,14 @@ class Player: Entity {
|
||||||
super(texture, frame, position);
|
super(texture, frame, position);
|
||||||
|
|
||||||
this.movementSpeed = movementSpeed;
|
this.movementSpeed = movementSpeed;
|
||||||
animationManager.add(KeyboardKey.KEY_NULL, Animation(texture, 6, 6, 0.15, 1));
|
animationManager.add(KeyboardKey.KEY_NULL, Animation(texture, 6, 5, 0.15, 1));
|
||||||
animationManager.add(KeyboardKey.KEY_W, Animation(texture, 6, 6, 0.1, 5));
|
animationManager.add(KeyboardKey.KEY_W, Animation(texture, 6, 5, 0.1, 5));
|
||||||
animationManager.add(KeyboardKey.KEY_S, Animation(texture, 6, 6, 0.1, 5));
|
animationManager.add(KeyboardKey.KEY_S, Animation(texture, 6, 5, 0.1, 5));
|
||||||
animationManager.add(KeyboardKey.KEY_A, Animation(texture, 6, 6, 0.1, 6));
|
animationManager.add(KeyboardKey.KEY_A, Animation(texture, 6, 5, 0.1, 5, true));
|
||||||
animationManager.add(KeyboardKey.KEY_D, Animation(texture, 6, 6, 0.1, 5));
|
animationManager.add(KeyboardKey.KEY_D, Animation(texture, 6, 5, 0.1, 5));
|
||||||
animationManager.add(KeyboardKey.KEY_SPACE, Animation(texture, 6, 6, 0.12, 2));
|
animationManager.add(KeyboardKey.KEY_SPACE, Animation(texture, 6, 5, 0.12, 2));
|
||||||
animationManager.add(KeyboardKey.KEY_X, Animation(texture, 6, 6, 0.1, 3));
|
animationManager.add(KeyboardKey.KEY_X, Animation(texture, 6, 5, 0.1, 3));
|
||||||
animationManager.add(KeyboardKey.KEY_Z, Animation(texture, 6, 6, 0.13, 4));
|
animationManager.add(KeyboardKey.KEY_Z, Animation(texture, 6, 5, 0.13, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
override void update() {}
|
override void update() {}
|
||||||
|
|
Loading…
Reference in New Issue