A small game engine for 2D games based of Raylib
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 

41 lignes
1.3 KiB

#include "components/sprite_component.h"
#include "entity.h"
#include "render_state.h"
ant::components::graphical::sprite_component::sprite_component(const std::string& str, int layer, ant::core::transform<> reposition, ant::core::Vec2<> scale)
// TODO: Textures should be managed by an asset manager
: current_texture(LoadTexture(str.c_str()))
, transform(reposition)
, m_scale(scale)
, m_layer(layer)
{}
void ant::components::graphical::sprite_component::render() {
Rectangle source = {
.x = 0,
.y = 0,
.width = static_cast<float>(current_texture.width),
.height = static_cast<float>(current_texture.height)
};
auto draw_position = owner()->world_transform();
draw_position = draw_position + transform;
Rectangle dest = {
.x = draw_position.position.X-transform.position.X,
.y = draw_position.position.Y-transform.position.Y,
.width = static_cast<float>(current_texture.width) * m_scale.X,
.height = static_cast<float>(current_texture.height) * m_scale.Y
};
ant::render::schedule_in_frame(m_layer, [current_texture = this->current_texture, dest, transform = this->transform, source, draw_position, m_scale = this->m_scale](){
DrawTexturePro(
current_texture,
source,
dest,
Vector2{
transform.position.X * m_scale.X,
transform.position.Y * m_scale.Y
},
draw_position.angle,
WHITE
);
});
}