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

Pages: [1]
1
So what to do? I don't want to use third-party libraries. I have to make it static because I have to reach the texture like this: TextureManager::GetTexture(TEXTURENAMES_FONT);

And it only occurs when I'm in release mode. If it didn't occur on debug mode, doesn't it mean that it works well? I don't get it.

Edit:
When I try to use the texture somewhere else, it did show. :O It only shows as white square in this code:

#include "InteriorPlan.hpp"
#include "../../AssetManagers/TextureManager/TextureManager.hpp"

const int backPlan[MapPlan::LENGTH] = {
        0, 0, 0, ...(I cropped out these data for simplicity) 0, 0, 0
};

const int midPlan[MapPlan::LENGTH] = {
        0, 0, 0, ...(I cropped out these data for simplicity) 0, 0, 0
};

const int frontPlan[MapPlan::LENGTH] = {
        0, 0, 0, ...(I cropped out these data for simplicity) 0, 0, 0
};

InteriorPlan::InteriorPlan() {

}

void InteriorPlan::Initialize() {
        int i = 0;
        for (i = 0; i < LENGTH; i++) {
                backTiles[i].SetPosition(sf::Vector2<float>((Tile::GetWidth()*(i % LENGTH)), (Tile::GetHeight()*(i / LENGTH))));
                backTiles[i].SetTexture(*TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR));
                backTiles[i].SetTextureStartPosition(sf::Vector2f(
                        Tile::GetWidth() * (backPlan[i] % TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().x),
                        Tile::GetHeight() * ((backPlan[i] / TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().y))));
        }

        for (i = 0; i < LENGTH; i++) {
                midTiles[i].SetPosition(sf::Vector2<float>((Tile::GetWidth()*(i % LENGTH)), (Tile::GetHeight()*(i / LENGTH))));
                midTiles[i].SetTexture(*TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR));
                midTiles[i].SetTextureStartPosition(sf::Vector2f(
                        Tile::GetWidth() * (midPlan[i] % TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().x),
                        Tile::GetHeight() * ((midPlan[i] / TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().y))));
        }

        for (i = 0; i < LENGTH; i++) {
                frontTiles[i].SetPosition(sf::Vector2<float>((Tile::GetWidth()*(i % LENGTH)), (Tile::GetHeight()*(i / LENGTH))));
                frontTiles[i].SetTexture(*TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR));
                frontTiles[i].SetTextureStartPosition(sf::Vector2f(
                        Tile::GetWidth() * (frontPlan[i] % TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().x),
                        Tile::GetHeight() * ((frontPlan[i] / TextureManager::GetTexture(TextureManager::TEXTURENAMES_TILES_INTERIOR)->getSize().y))));
        }
}

void InteriorPlan::Draw() {
        MapPlan::Draw();
}
 

2
Graphics / Some textures become white square when I'm in release mode.
« on: March 01, 2018, 11:37:14 pm »
Hi. I have a question again.  ::) Recently, I tried to show tiles on the screen, and there were 2500x3 sprites on the screen. I tried to render them all and it got slow. I tried to render a portion of them according to their position but it didn't work either. It got slow again. I'm always re instantiating the Sprite in a function in draw calls, maybe because of it, but what to do? When I declare the sf::Sprite in class declaration, it gives error when I try to call Window->Draw(sf::Sprite); It's weird.

Whatever, my here is my question: It basically doesn't draw some of my texture on the screen, actually just one texture. You can see texture_interior.png on the code:

#include "TextureManager.hpp"
#include <iostream>

sf::Texture TextureManager::textures[TEXTURENAMES_TEXTURECOUNT];
std::string TextureManager::texturePaths[TEXTURENAMES_TEXTURECOUNT];

TextureManager::TextureManager() {
        texturePaths[TEXTURENAMES_ARROWS] = "Bitmaps/System/arrows.png";
        texturePaths[TEXTURENAMES_BUTTONS] = "Bitmaps/System/buttons.png";
        texturePaths[TEXTURENAMES_FADE] = "Bitmaps/System/fade.png";
        texturePaths[TEXTURENAMES_FONT] = "Bitmaps/System/game_font.png";
        texturePaths[TEXTURENAMES_ICON] = "Bitmaps/System/icon.png";
        texturePaths[TEXTURENAMES_LANGUAGES] = "Bitmaps/System/languages.png";
        texturePaths[TEXTURENAMES_SHINE] = "Bitmaps/System/shine.png";
        texturePaths[TEXTURENAMES_LOGO] = "Bitmaps/System/system_logo.png";
        texturePaths[TEXTURENAMES_WHITEBRUSH] = "Bitmaps/System/white_brush.png";
        texturePaths[TEXTURENAMES_CHARBODY] = "Bitmaps/Character/Base/tileset_character_body.png";
        texturePaths[TEXTURENAMES_CHARDRESS] = "Bitmaps/Character/Armor/tileset_character_dress.png";
        texturePaths[TEXTURENAMES_CHARTOKA] = "Bitmaps/Character/Accessory/tileset_character_toka.png";
        texturePaths[TEXTURENAMES_CHARHAIR] = "Bitmaps/Character/Helmet/tileset_character_hair.png";
        texturePaths[TEXTURENAMES_WEAPONKIZILCIKSOPASI] = "Bitmaps/Character/Weapon/weapon_kizilcik_sopasi.png";
        texturePaths[TEXTURENAMES_TILES_INTERIOR] = "Bitmaps/Environment/tiles_interior.png";
        texturePaths[TEXTURENAMES_TILES_FOREST] = "Bitmaps/Environment/tiles_forest.png";
        texturePaths[TEXTURENAMES_EMPTY] = "Bitmaps/System/empty.png";
}

bool TextureManager::Initialize() {
        if (!SetTextures()) {
                return false;
        } else {
                return true;
        }
}

bool TextureManager::SetTextures() {
        bool textureLoadedCorrectly = true;
        for (int i = 0; i < TEXTURENAMES_TEXTURECOUNT; i++) {
                if (!textures[i].loadFromFile(texturePaths[i])) {
                        textureLoadedCorrectly = false;
                        break;
                }
        }

        return textureLoadedCorrectly;
}

sf::Texture* TextureManager::GetTexture(const int textureName) {
        return &textures[textureName];
}
 

Thank you so much. I don't know what to present more, so please ask more if you didn't understand a thing. (I didn't understand too actually :D)

3
I don't get it. Now it works like charm. Thank you.  ???

4
Audio / Access violation when trying to play music in the wrapper class.
« on: February 18, 2018, 01:24:45 pm »
Hello all. I'm wrapping sf::SoundBuffer and sf::Sound classes in a class named SoundObject. It is followed like this:

SoundObject.h
#ifndef SOUNDOBJECT_H
#define SOUNDOBJECT_H

#include <string>
#include <SFML/Audio.hpp>

class SoundObject {
public:
        SoundObject();
        bool Create(std::string filename);
        void Play();
private:
        sf::Sound soundInstance;
        sf::SoundBuffer soundBuffer;
};

#endif

 

SoundObject.cpp
#include "SoundObject.h"
#include <string>
#include "../GameProperties/GameProperties.h"

SoundObject::SoundObject() {

}

bool SoundObject::Create(std::string filename) {
        if (!soundBuffer.loadFromFile(filename)) {
                return false;
        }

        soundInstance.setBuffer(soundBuffer);

        return true;
}

void SoundObject::Play() {
        soundInstance.setVolume(GameProperties::GetSFXVolume());
        soundInstance.play();
}
 

And I'm calling these functions in a class like this:
if (!changeSound.Create("Sounds/System/sound_change.ogg")) {
                return false;
        }

        if (!selectSound.Create("Sounds/System/sound_select.ogg")) {
                return false;
        }
 

changeSound and selectSound is member of a class.

But it gives access violation error. When I try to play the sounds in the main function, it doesn't give error. I don't get it. Can you help me?

Thanks.

5
Graphics / Re: Access violation when trying to load texture from file.
« on: February 15, 2018, 08:33:50 pm »
Yes I am lack of experience about C++. Thanks, I'll try. ^^

6
Graphics / Re: Access violation when trying to load texture from file.
« on: February 15, 2018, 06:54:50 pm »
Yes but you said that I didn't create the sprite. If it has a default constructor, why the program didn't create it? I fixed the problem with this approach, but I don't know if this is an expensive thing to process for RAM.

void GUIElement::Draw(sf::RenderWindow& window) {
        sf::Sprite sprite;
        sprite.setTexture(texture);
        sprite.setColor(sf::Color(255, 255, 255));
        window.draw(sprite);
}
 

7
Graphics / Re: Access violation when trying to load texture from file.
« on: February 15, 2018, 06:25:41 pm »
How to create the sprite? I deleted pointers and now they are pure types.

8
Graphics / Access violation when trying to load texture from file.
« on: February 15, 2018, 05:58:10 pm »
Hi, I recently faced an access violation error. I was wrapping the sf::Texture and sf::Sprite classes into a GameObject class. Here is the data structure:

>Bitmaps
  >System
     >system_logo.png
>Framework
  >System
    >EventManager
    >GameObject
    >GUIElement
    >MusicObject
    >SoundObject
    >WindowManager
>Stages
  >LanguageSelect
  >Stage
  >Title
>main.cpp

main.cpp
#include "Framework/System/WindowManager/WindowManager.h"
#include "Framework/System/EventManager/EventManager.h"
#include "Framework/System/GameProperties/GameProperties.h"
#include "Framework/System/InputManager/InputManager.h"
#include "Stages/Stage/Stage.h"
#include "Stages/LanguageSelect/LanguageSelect.h"
#include "Stages/Title/Title.h"

int main()
{
        GameProperties gameProperties;

        WindowManager windowManager(640, 360, "Rabid Streets", false);
        EventManager eventManager;
        InputManager inputManager;

        Stage* currentStage;

        bool languageSelected = false;

        if (languageSelected == false) {
                currentStage = &LanguageSelect();
        }
        else {
                currentStage = &Title();
        }

        if (!currentStage->Initialize()) {
                //return 0;
        }

        while (windowManager.WindowIsOpen()) {

                while (windowManager.PollEvents(eventManager.GetEvents())) {
                        if (eventManager.IsLostFocus()) {
                                gameProperties.SetIsGamePaused(true);
                        }
                }

                currentStage->Render();

                windowManager.ClearWindow();

                currentStage->Draw();

                windowManager.DisplayWindowContents();
        }

        currentStage->Destroy();

    return 0;
}


 

LanguageSelect.cpp
#include "LanguageSelect.h"
#include "../../Framework/System/WindowManager/WindowManager.h"

LanguageSelect::LanguageSelect() {

}

bool LanguageSelect::Initialize() {
        //logo is initialized
        sf::Texture texLogo;
        if (!texLogo.loadFromFile("Bitmaps/System/system_logo.png")) {
                return false;
        }
        logo.SetTexture(texLogo);
        logo.SetGameObjectPosition(320, 50);

        return true;
}

void LanguageSelect::Render() {

}

void LanguageSelect::Draw() {
        logo.Draw(&WindowManager::GetWindow());
}

void LanguageSelect::Destroy() {
       
}
 

LanguageSelect.h
#ifndef LANGUAGESELECT_H
#define LANGUAGESELECT_H

#include "../Stage/Stage.h"
#include <SFML/Graphics.hpp>
#include "../../Framework/System/GUIElement/GUIElement.h"

class LanguageSelect : public Stage {
public:
        LanguageSelect();
        bool Initialize();
        void Render();
        void Draw();
        void Destroy();
private:
        GUIElement logo;
};

#endif
 

GUIElement.cpp
#include "GUIElement.h"
#include <iostream>

GUIElement::GUIElement() {
       
}

void GUIElement::SetGameObjectPosition(float xP, float yP) {
        x = xP;
        y = yP;

        RefreshPosition();
}

void GUIElement::Draw(sf::RenderWindow* window) {
        window->draw(*sprite);
}

void GUIElement::SetTexture(sf::Texture& tex) {
        texture = &tex;

        std::cout << texture << std::endl;

        sprite->setTexture(tex);

        sprite->setOrigin(sf::Vector2f(sprite->getTexture()->getSize().x * 0.5f, sprite->getTexture()->getSize().y * 0.5f));
}

void GUIElement::SetSpriteRect(int rX, int rY, int rWidth, int rHeight) {
        sprite->setTextureRect(sf::IntRect(rX, rY, rWidth, rHeight));
}

void GUIElement::SetX(float value) {
        x = value;

        RefreshPosition();
}

void GUIElement::SetY(float value) {
        y = value;

        RefreshPosition();
}

float GUIElement::GetX() {
        return x;
}

float GUIElement::GetY() {
        return y;
}

void GUIElement::Move(float xP, float yP) {
        x += xP;
        y += yP;

        RefreshPosition();
}

void GUIElement::SetColor(sf::Color color) {
        sprite->setColor(color);
}

void GUIElement::RefreshPosition() {
        sprite->setPosition(sf::Vector2f(x, y));
}
 

GUIElement.h
#ifndef GUIELEMENT_H
#define GUIELEMENT_H

#include <SFML/Graphics.hpp>

class GUIElement {
public:
        GUIElement();
        void SetGameObjectPosition(float xP, float yP);
        void Draw(sf::RenderWindow* window);
        void SetTexture(sf::Texture& tex);
        void SetSpriteRect(int rX, int rY, int rWidth, int rHeight);
        void SetX(float value);
        void SetY(float value);
        float GetX();
        float GetY();
        void Move(float x, float y);
        void SetColor(sf::Color color);
protected:
        sf::Texture* texture;
        sf::Sprite* sprite;
        float x;
        float y;
private:
        void RefreshPosition();
};

#endif
 

This function gives error:

void GUIElement::SetTexture(sf::Texture& tex) {
        texture = &tex;

        std::cout << texture << std::endl;

        sprite->setTexture(tex);

        sprite->setOrigin(sf::Vector2f(sprite->getTexture()->getSize().x * 0.5f, sprite->getTexture()->getSize().y * 0.5f));
}
 

This line:
sprite->setTexture(tex);
 

Thanks.

9
Window / Re: isOpen() returns false and window shuts down immediately.
« on: February 13, 2018, 08:09:07 pm »
Thank you. It works now!!!  ;D

10
Window / Re: isOpen() returns false and window shuts down immediately.
« on: February 13, 2018, 07:58:00 pm »
Thank you so much. What should I do? I don't want to use new keyword because of memory leakage. Using of new keyword is mandatory?

11
Window / isOpen() returns false and window shuts down immediately.
« on: February 13, 2018, 07:24:51 pm »
Hi all. I'm new to the SFML and the forum and I had some issues today. First of all, I want to use classes with SFML and I made a framework for this. File Structure is like this:

>main.cpp
>Framework>Window>Window.h and Window.cpp

Framework and main.cpp are at the same level. Window class lies beneath the framework folder.

main.cpp:
#include "Framework\Window\Window.h"
#include <iostream>
#include <SFML/Graphics.hpp>

int main()
{
        Window window(640, 360, "Title", false);

        while (window.IsOpen()) {
                window.Clear();
                window.Draw();
        }

    return 0;
}

 

Window.h
#ifndef WINDOW_H
#define WINDOW_H

#include <string>
#include <SFML/Graphics.hpp>

class Window {
public:
        Window(int width, int height, std::string title, bool fullscreen);
        bool IsOpen();
        void Clear();
        void Draw();
private:
        sf::RenderWindow* window;
        int windowWidth;
        int windowHeight;
        std::string windowTitle;
        bool windowFullscreen;
};

#endif
 

Window.cpp
#include "Window.h"

Window::Window(int width, int height, std::string title, bool fullscreen) {
        windowWidth = width;
        windowHeight = height;
        windowTitle = title;
        windowFullscreen = fullscreen;

        window = &sf::RenderWindow(sf::VideoMode(windowWidth, windowHeight), windowTitle, sf::Style::Close | sf::Style::Titlebar);

        window->setFramerateLimit(60);
}

bool Window::IsOpen() {
        return window->isOpen();
}

void Window::Clear() {
        window->clear();
}

void Window::Draw() {
        window->display();
}
 

What is the problem. Does SFML supports object oriented programming? By the way, clear function gives access violation error in the code.

Thanks.

Pages: [1]
anything