Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - abdpheonix77

Pages: [1]
1
Graphics / Re: I don't understand why it won't render my sprite.
« on: May 10, 2019, 07:03:31 pm »
Oh my god you a real life saver thank you I have spent too much time not knowing what was wrong :)))!

2
Graphics / I don't understand why it won't render my sprite.
« on: May 10, 2019, 06:17:10 pm »
It's my first time coding a game in SFML and I need some help cause I really don't know what the problem is.

types.cpp
PlayingCard::PlayingCard()
{
    sf::Texture temp;
    std::string path="Graphics/Cards/";
    ++counter_num;
    if(counter_num>13){
        counter_num=1;
        ++counter_suit;
    }
    number=counter_num;
    suit=counter_suit;
    if(number==1){
        path = path + "A";
    }
    else
        if(number==11){
            path = path + "J";
        }
        else
            if(number==12){
                path = path + "Q";
            }
            else
                if(number==13){
                    path = path + "K";
                }
                else
                    if(number==10)
                        path = path + '1'+'0';
                    else
                        path = path + (char)(number+'0');
    path = path + "_of_";
    if(suit==1)
        path = path + "diamonds";
    else
        if(suit==2)
            path = path + "clubs";
        else
            if(suit==3)
                path = path + "hearts";
            else
                path = path + "spades";
    path = path + ".png";
    temp.loadFromFile(resourcePath()+path);
    _sprite.setTexture(temp);
    //std::cout<<path<<"\n";
}

sf::Sprite PlayingCard::get_sprite()
{
    return _sprite;
}

game.cpp
#include "game.hpp"

PlayingCard x;

Game::Game() : _window(sf::VideoMode(1200, 700),"POKER")
{
    sf::Texture temp;
    temp.loadFromFile(resourcePath()+"Graphics/background.png");
    _background.setTexture(temp);
    Game::run(240);
}

///Game related functions

void Game::run(int minimum_frame_per_seconds) {
    sf::Clock clock;
    sf::Time timeSinceLastUpdate;
    sf::Time TimePerFrame = sf::seconds(1.f/minimum_frame_per_seconds);
    while (_window.isOpen()) {
        processEvents();
        timeSinceLastUpdate = clock.restart();
        while (timeSinceLastUpdate > TimePerFrame) {
            timeSinceLastUpdate -= TimePerFrame;
            update(TimePerFrame);
        }
        update(timeSinceLastUpdate);
        render();
    }
}

void Game::processEvents()
{
    sf::Event event;
    while(_window.pollEvent(event)){
        if(event.type==sf::Event::Closed)
            _window.close();
    }
}

void Game::update(sf::Time deltaTime){
}

void Game::render() {
    _window.clear();
    _window.draw(_background);
    _window.draw(x.get_sprite());
    _window.display();
}

It should render my sprite but only renders a white sized rectangle.

Pages: [1]
anything