Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#pragma once
#include "Components.h"
#include "SDL.h"
#include "TransformComponent.h"
class SpriteComp :public Comp
{
private:
TransformComp *transform;
SDL_Texture *texture;
SDL_Rect srcRect, destRect;
public:
SpriteComp() = default;
SpriteComp(const char* path)
{
texture = TextureManager::LoadTexture(path);
}
void init() override {
transform = &entity->getComp<TransformComp>();
srcRect.x = srcRect.y = 0;
srcRect.w = srcRect.h = 32;
destRect.w = destRect.h = 64;
}
void update() override {
destRect.x = (int)transform->position.x;
destRect.y = (int)transform->position.y;
}
void draw() override {
Manager::Draw(texture, srcRect, destRect);
}
};