Commit 2ae43731 authored by TTV19SP Saarinen Meri Tuulia Kyllikki's avatar TTV19SP Saarinen Meri Tuulia Kyllikki
Browse files

Tekstiluokka lisätty

parent c688ffbc
......@@ -5,6 +5,7 @@
#include "../include/GameObject.h"
#include "../include/Component.h"
#include "../include/Sprite.h"
#include "../include/Text.h"
class Application {
public:
......@@ -15,6 +16,7 @@ public:
bool isRunning();
GameObject* newGameObject(std::string name = "GameObject");
Sprite* newSprite(std::string imagePath);
Text* newText(std::string FontFile, sf::Color color, int size);
std::vector<GameObject*> gameObjects;
std::vector<Component*> components;
private:
......
#pragma once
#include <SFML/Graphics.hpp>
#include <string>
#include "../include/Component.h"
class Text : public Component {
friend class Application;
public:
Text(std::string fontFile, sf::Color color, int size);
~Text();
private:
void draw(sf::RenderWindow* window, sf::Transform transform);
sf::Text text;
sf::Font font;
};
\ No newline at end of file
......@@ -70,6 +70,12 @@ Sprite* Application::newSprite(std::string imagePath) {
return spr;
}
Text* Application::newText(std::string fontFile, sf::Color color, int size){
Text* txt = new Text(fontFile, color, size);
components.push_back(txt);
return txt;
}
bool Application::isRunning() {
return window->isOpen();
}
\ No newline at end of file
#include "../include/Text.h"
Text::Text(std::string fontFile, sf::Color color, int size){
font.loadFromFile("arial.ttf");
if (!font.loadFromFile("arial.ttf"))
{
//Error
}
text.setFont(font);
text.setString(fontFile);
text.setColor(color);
text.setCharacterSize(size);
}
Text::~Text(){
}
void Text::draw(sf::RenderWindow* window, sf::Transform transform) {
window->draw(text, transform);
}
\ No newline at end of file
......@@ -3,8 +3,10 @@
#include "../include/GameObject.h"
#include "../include/Component.h"
#include "../include/Sprite.h"
#include "../include/Text.h"
void NewCard(float x, float y, Sprite* sprite);
void NewText(float x, float y, Text* text);
Application* app;
......@@ -14,6 +16,9 @@ int main() {
app = new Application(1280, 720);
sf::Clock clock;
Text* title = app->newText("Muistipeli", sf::Color::White, 50);
NewText(-100.0f, -350.0f, title);
Sprite* cardSprite = app->newSprite("card.png");
NewCard(-300.0f, 150.0f, cardSprite);
NewCard(-100.0f, 150.0f, cardSprite);
......@@ -44,4 +49,11 @@ void NewCard(float x, float y, Sprite* sprite) {
card->addComponent(sprite);
card->scale = sf::Vector2f(0.5f, 0.5f);
card->position = sf::Vector2f(x, y);
}
void NewText(float x, float y, Text* text) {
GameObject* title = app->newGameObject("Title");
title->addComponent(text);
title->position = sf::Vector2f(x, y);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment