Compare commits
No commits in common. "447cb4cd7aee7721d0c15687cc2d0fab4e3eccd9" and "72496226d8edadd15149758cc5b7c8ce4bdb6e27" have entirely different histories.
447cb4cd7a
...
72496226d8
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,7 +15,3 @@ cmake-build-debug/
|
||||
output.txt
|
||||
buildall.bat
|
||||
typer.py
|
||||
|
||||
# Sandbox Assets
|
||||
assets/
|
||||
art/
|
||||
|
@ -1,18 +1,8 @@
|
||||
#include "sprite_component.h"
|
||||
#include <raylib.h>
|
||||
|
||||
#include "Logger.h"
|
||||
#include "transform_component.h"
|
||||
|
||||
|
||||
void SpriteComponent::Render(float x, float y) const {
|
||||
if (texture) {
|
||||
DrawTexture(*reinterpret_cast<Texture2D*>(texture), x, y, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteComponent::Render(TransformComponent transform) const {
|
||||
if (texture) {
|
||||
DrawTexture(*reinterpret_cast<Texture2D*>(texture), transform.x, transform.y, WHITE);
|
||||
}
|
||||
}
|
@ -1,13 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "transform_component.h"
|
||||
|
||||
|
||||
struct SpriteComponent {
|
||||
public:
|
||||
void* texture; // void* to abstract Texture2D
|
||||
void Render(float x, float y) const;
|
||||
void Render(TransformComponent transform) const;
|
||||
};
|
||||
|
||||
// Usage:
|
||||
|
@ -26,30 +26,14 @@ public:
|
||||
|
||||
void UpdateActiveScene() {
|
||||
if (activeScene != entt::null) {
|
||||
// Iterate over entities in the active scene that have an InputComponent
|
||||
auto view = registry.view<InputComponent>();
|
||||
for (auto entity : view) {
|
||||
auto& inputComponent = view.get<InputComponent>(entity);
|
||||
inputComponent.Update(); // This will call the input logic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderActiveScene() {
|
||||
if (activeScene != entt::null) {
|
||||
// Iterate over entities in the active scene that have both SpriteComponent and TransformComponent
|
||||
auto view = registry.view<SpriteComponent, TransformComponent>();
|
||||
for (auto entity : view) {
|
||||
auto& sprite = view.get<SpriteComponent>(entity);
|
||||
auto& transform = view.get<TransformComponent>(entity);
|
||||
|
||||
// Render the sprite at the position defined by the TransformComponent
|
||||
sprite.Render(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
entt::registry& registry;
|
||||
entt::entity activeScene;
|
||||
|
Loading…
x
Reference in New Issue
Block a user