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 - KuziNs

Pages: [1]
1
Graphics / Re: C++ SFML 2.2 graphics not rendering
« on: June 08, 2015, 08:50:54 pm »
Yeah, well I was just expermenting with stuff and how it all works. I don't really need like super efficient and super correct code. Just wanted to know, WHY it doesn't work as I expected to.

2
Graphics / Re: C++ SFML 2.2 graphics not rendering
« on: June 08, 2015, 08:45:16 pm »
Okay, I don't understand anything of that stuff. :D.

3
Graphics / Re: C++ SFML 2.2 graphics not rendering
« on: June 08, 2015, 07:24:46 pm »
No I have c++ in Visual Studio 2013.

As it goes for rendering I have that in main.cpp where there is window.clear(); and window.display();

#include <Windows.h>
#include <iostream>

#include "game_state.h"
#include "main_menu.h"


game_state coreState;
bool quitGame = false;

int main()
{
        sf::RenderWindow window(sf::VideoMode(1024, 640), "Game");

        window.setMouseCursorVisible(false);

        coreState.SetWindow(&window);
        coreState.SetState(new main_menu());

        sf::Clock timer;
        sf::Time elapsed;

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                elapsed = timer.getElapsedTime();
                if (elapsed.asMicroseconds() > 16666)
                {
                        window.clear(sf::Color::Black);

                        coreState.Update();
                        coreState.Render();

                        window.display();

                        if (quitGame)
                        {
                                window.close();
                        }
                        timer.restart();
                }
        }
        return 0;
}

4
Graphics / C++ SFML 2.2 graphics not rendering
« on: June 08, 2015, 07:14:24 pm »
I'm just playing around with C++ SFML stuff and I kinda don't understand why my code isn't working. The thing I want to do is to draw like let's say 5, squares in Window randomly placed around the screen using vector, but I don't understand why it's not working. And it doesn't give any error as well, I can open game like normal, but it's just not rendering.

This is the main game class:

#include "main_game.h"
#include "main_menu.h"

void main_game::Initialize(sf::RenderWindow* window)
{
    this->Player = new player();
    this->Player->setOrigin(this->Player->getGlobalBounds().width / 2, this->Player->getGlobalBounds().height / 2);

    this->TestObject = new testObject();
    this->TestObject->Initialize();
    this->TestObject->setOrigin(this->TestObject->getGlobalBounds().width / 2, this->TestObject->getGlobalBounds().height / 2);
}

void main_game::Update(sf::RenderWindow* window)
{
    this->Player->setPosition(sf::Mouse::getPosition(*window).x, sf::Mouse::getPosition(*window).y);
    this->Player->Update();

    if (this->Player->CheckCollision(TestObject))
    {
        this->TestObject->setColor(sf::Color::Red);
    }
    else
    {
        this->TestObject->setColor(sf::Color::Cyan);
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
    {
        coreState.SetState(new main_menu());
    }
}

void main_game::Render(sf::RenderWindow* window, std::vector<sf::Sprite> sprites)
{
    this->TestObject->Render(*window, sprites);

    window->draw(*this->Player);
}

void main_game::Destroy(sf::RenderWindow* window)
{
    delete this->Player;
    delete this->TestObject;
}

This is the testObject.h class

#pragma once

#include "entity.h"

class testObject : public Entity
{
public:
    testObject();
    void Initialize();
    void Render(sf::RenderWindow &window, std::vector<sf::Sprite> sprites);
    void Update();
private:
    sf::RenderWindow window;
};

And this is testObject.cpp class

#include "testObject.h"

testObject::testObject()
{
    this->Load("testObject.png");
}

void testObject::Initialize()
{
    sf::Texture testObjectTexture;
    sf::Sprite testObjectSprite;

    testObjectTexture.loadFromFile("testObject.png");
    testObjectSprite.setTexture(testObjectTexture);

    std::vector<sf::Sprite> sprites(5, sf::Sprite(testObjectSprite));

    srand(time(0));

    for (unsigned int i = 0; i < sprites.size(); i++)
    {
        sprites[i].setPosition(1 + (rand() % 1024 - 32), rand() % 640 - 32);
    }
}

void testObject::Render(sf::RenderWindow &window, std::vector<sf::Sprite> sprites)
{
    for (unsigned int i = 0; i < sprites.size(); i++)
    {
        window.draw(sprites[i]);
    }
}

void testObject::Update()
{
    Entity::Update();
}

5
Graphics / C++ SFML 2.2 vectors
« on: June 08, 2015, 05:05:22 pm »
I'm just playing around with C++ SFML stuff and I kinda don't understand why my code isn't working. The thing I want to do is to draw like let's say 5, squares in Window randomly placed around the screen using vector, but I don't understand why it's not working.

This is the main game class:

#include "main_game.h"
#include "main_menu.h"

void main_game::Initialize(sf::RenderWindow* window)
{
    this->Player = new player();
    this->Player->setOrigin(this->Player->getGlobalBounds().width / 2, this->Player->getGlobalBounds().height / 2);

    this->TestObject = new testObject();
    this->TestObject->Initialize();
    this->TestObject->setOrigin(this->TestObject->getGlobalBounds().width / 2, this->TestObject->getGlobalBounds().height / 2);
}

void main_game::Update(sf::RenderWindow* window)
{
    this->Player->setPosition(sf::Mouse::getPosition(*window).x, sf::Mouse::getPosition(*window).y);
    this->Player->Update();

    if (this->Player->CheckCollision(TestObject))
    {
        this->TestObject->setColor(sf::Color::Red);
    }
    else
    {
        this->TestObject->setColor(sf::Color::Cyan);
    }

    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
    {
        coreState.SetState(new main_menu());
    }
}

void main_game::Render(sf::RenderWindow* window, std::vector<sf::Sprite> sprites)
{
    this->TestObject->Render(*window, sprites);

    window->draw(*this->Player);
}

void main_game::Destroy(sf::RenderWindow* window)
{
    delete this->Player;
    delete this->TestObject;
}


This is the testObject.h class

#pragma once

#include "entity.h"

class testObject : public Entity
{
public:
    testObject();
    void Initialize();
    void Render(sf::RenderWindow window, std::vector<sf::Sprite> sprites);
    void Update();
private:
    sf::RenderWindow window;
};


And this is testObject.cpp class

#include "testObject.h"

testObject::testObject()
{
    this->Load("testObject.png");
}

void testObject::Initialize()
{
    sf::Texture testObjectTexture;
    sf::Sprite testObjectSprite;

    testObjectTexture.loadFromFile("testObject.png");
    testObjectSprite.setTexture(testObjectTexture);

    std::vector<sf::Sprite> sprites(5, sf::Sprite(testObjectSprite));

    srand(time(0));

    for (unsigned int i = 0; i < sprites.size(); i++)
    {
        sprites[i].setPosition(1 + (rand() % 1024 - 32), rand() % 640 - 32);
    }
}

void testObject::Render(sf::RenderWindow window, std::vector<sf::Sprite> sprites)
{
    for (unsigned int i = 0; i < sprites.size(); i++)
    {
        window.draw(sprites[i]);
    }
}

void testObject::Update()
{
    Entity::Update();
}


The error message is

1>------ Build started: Project: Blahblah, Configuration: Debug Win32 ------
1>  testObject.cpp
1>d:\visual studio projects\blahblah\blahblah\testobject.cpp(18): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>d:\visual studio projects\blahblah\blahblah\testobject.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>  main_game.cpp
1>d:\visual studio projects\blahblah\blahblah\main_game.cpp(16): warning C4244: 'argument' : conversion from 'int' to 'float', possible loss of data
1>d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\window\window.hpp(521): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1>          d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1>          d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::Window::Window(const sf::Window &)'
1>d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\graphics\rendertarget.hpp(419): error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
1>          d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\system\noncopyable.hpp(67) : see declaration of 'sf::NonCopyable::NonCopyable'
1>          d:\visual studio projects\blahblah\3rdpartylibs\include\sfml\system\noncopyable.hpp(42) : see declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function 'sf::RenderTarget::RenderTarget(const sf::RenderTarget &)'
1>  Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Pages: [1]