tower-defense-cpp/Button.cpp
bMorgan01 b49080f675 init
2022-03-08 10:18:34 -07:00

33 lines
814 B
C++

//
// Created by Benjamin on 1/25/2022.
//
#include "Button.h"
Button::Button(const sf::Texture &texture, const std::function<void()> &command) : Sprite(texture) {
this->command = command;
}
Button::Button(const sf::Texture &texture, float x, float y, float scale, int origin, const std::function<void()> &command) : Sprite(texture, x, y, scale, origin) {
this->command = command;
}
void Button::click() {
command();
}
void Button::hover() {
Sprite::hover();
sf::Vector2f pos = getPosition();
setScale(getScale().x + 0.1, getScale().x + 0.1);
setPosition(pos.x, pos.y);
}
void Button::unHover() {
Sprite::unHover();
sf::Vector2f pos = getPosition();
setScale(getScale().x - 0.1, getScale().x - 0.1);
setPosition(pos.x, pos.y);
}