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

Pages: [1]
1
Graphics / Re: How to Fix White Square?
« on: May 05, 2013, 11:42:27 pm »
Does textureManager keep it? if so then your tile should reference the texture from texture manager.

After calling myself an idiot after seeing what I did wrong...

I...

I love you. q-q

Kidding, but I did manage to solve it. Thanks for that! And I've already learned the C++ basics, but all-out OOP is still new ground for me.

2
Graphics / How to Fix White Square?
« on: April 30, 2013, 06:26:08 pm »
I already read the section for this issue on the Tutorials page, and I've read some instances of this issue around the forums; the problem is that none of this helps me much.

Since I'm a newbie at C++, I don't know the proper way to "extend the texture's lifetime as long as they are used by sprites." I was hoping someone would be able to help me fix this.

I'm currently using just a temporary method (for the purpose of testing) to draw a sprite to the window. This is all taking place within Engine:

Engine.h
#ifndef Engine_h
#define Engine_h

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

#include "TextureManager.h"
#include "Tile.h"

class Engine
{
    private:
        sf::RenderWindow* window;
   
        bool Initialize();
        void MainLoop();
        void ProcessInput();
        void RenderFrame();
        void Update();
       
        TextureManager textureManager;
        void LoadImages();
       
        Tile* testTile;
   
   
    public:
        Engine();
        ~Engine();
   
        void Go();
   
        sf::Texture BackgroundTexture;
        sf::Sprite Background;
};

#endif
 

Engine.cpp
#include <iostream>

#include "Engine.h"

Engine::Engine()
{
   
}

Engine::~Engine()
{
    delete window;
}




bool Engine::Initialize()
{
    window = new sf::RenderWindow(sf::VideoMode(800, 612, 32), "BattleGame - V2");
   
    if(!window)
        return false;
    else if(!BackgroundTexture.loadFromFile("BattleGame.app/Contents/Resources/BG.png"))
            return false;
         else
            Background.setTexture(BackgroundTexture);
            LoadImages();
            return true;
}




void Engine::ProcessInput()
{
    sf::Event Event;
   
    while(window->pollEvent(Event))
    {
        switch(Event.type)
        {
            case sf::Event::Closed:
                window->close();
                break;
        }
    }
}




void Engine::MainLoop()
{
    while(window->isOpen())
    {
        ProcessInput();
        Update();
        RenderFrame();
    }
}




void Engine::Update()
{
   
}




void Engine::LoadImages()
{
    sf::Texture sprite;
    sprite.loadFromFile("BattleGame.app/Contents/Resources/ConsoleGUI.png");
   
    textureManager.AddTexture(sprite);
    testTile = new Tile(sprite);
}




void Engine::RenderFrame()
{
    window->clear();
    window->draw(Background);
    testTile->Draw(0, 486, window);
    window->display();
}




void Engine::Go()
{
    if(!Initialize())
        throw "The engine failed to initialize.";
    else
        MainLoop();
}
 

3
General / Debug EXC_BAD_ACCESS?
« on: April 28, 2013, 08:47:52 pm »
This might be an Xcode 4-only issue, though I figured one or two people here have come across it.

After following RevTorA's tutorial for a C++ Tile Engine, I came across this nasty bug when trying to set a position to an element. It seems that for us Mac devs, EXC_BAD-ACCESS points out a memory issue. The only problem is that Xcode isn't giving me a way to fix it, as would usually be the case.

The app would build and then run almost perfectly, except that this issue messes up rendering pretty badly. I was wondering if anyone here could help me out by pointing out how to fix it.

Tile.h
#ifndef Tile_h
#define Tile_h

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

class Tile
{
    private:
        sf::Sprite baseSprite; // The trouble child.
       
   
    public:
        Tile(sf::Texture& texture);
        ~Tile();
   
        void Draw(int x, int y, sf::RenderWindow* renderWindow);
       
};

#endif
 

Tile.cpp
#include "Tile.h"

Tile::Tile(sf::Texture& texture)
{
    baseSprite.setTexture(texture);
}

Tile::~Tile()
{
   
}

void Tile::Draw(int x, int y, sf::RenderWindow* renderWindow)
{
    baseSprite.setPosition(x, y); // This is where the EXC_BAD_ACCESS occurs.
    renderWindow->draw(baseSprite);
}
 

Those were the Tile files, which are the origin of the issue. These are the two compadres that reference Tile at some point.

Engine.h
#ifndef Engine_h
#define Engine_h

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

#include "TextureManager.h"
#include "Tile.h"

class Engine
{
    private:
        sf::RenderWindow* window;
   
        bool Initialize();
        void MainLoop();
        void ProcessInput();
        void RenderFrame();
        void Update();
       
        TextureManager* textureManager;
        void LoadImages();
   
        Tile* testTile;
   
   
    public:
        Engine();
        ~Engine();
   
        void Go();
   
        sf::Texture BackgroundTexture;
        sf::Sprite Background;
};

#endif
 

Engine.cpp
#include <iostream>

#include "Engine.h"

Engine::Engine()
{
   
}

Engine::~Engine()
{
    delete window;
    delete textureManager;
}


bool Engine::Initialize()
{
    textureManager = new TextureManager();
    window = new sf::RenderWindow(sf::VideoMode(800, 612, 32), "BattleGame - V2");
   
    if(!window)
        return false;
    else if(!BackgroundTexture.loadFromFile("BattleGame.app/Contents/Resources/BG.png"))
            return false;
         else
            Background.setTexture(BackgroundTexture);
            return true;
}


void Engine::ProcessInput()
{
    sf::Event Event;
   
    while(window->pollEvent(Event))
    {
        switch(Event.type)
        {
            case sf::Event::Closed:
                window->close();
                break;
        }
    }
}


void Engine::MainLoop()
{
    while(window->isOpen())
    {
        ProcessInput();
        Update();
        RenderFrame();
    }
}


void Engine::Update()
{
   
}


void Engine::LoadImages()
{
    sf::Texture sprite;
    sprite.loadFromFile("BattleGame.app/Contents/Resources/ConsoleGUI.png");
   
    textureManager->AddTexture(sprite);
   
    testTile = new Tile(textureManager->GetTexture(0));
}


void Engine::RenderFrame()
{
    window->clear();
    window->draw(Background);
    testTile->Draw(100, 0, window);
    window->display();
}


void Engine::Go()
{
    if(!Initialize())
        throw "The engine failed to initialize.";
    else
        MainLoop();
}
 

Anyone?

4
Graphics / Re: Background Image Not Loading
« on: April 25, 2013, 04:29:56 pm »
Your texture is loaded after the function returns. The code is never executed.

So I have to set the texture before I create the window?

EDIT: Did that and it works fine. I guess initializing the graphics before trying to draw them would be smart.  :-\

5
Graphics / [SOLVED] Background Image Not Loading
« on: April 25, 2013, 03:14:48 pm »
While the subject title sounds retarded and newbish, it's actually an interesting problem. I am a newbie at C++ coding, and SFML is just another layer of stuff for me to learn.

The general issue is simple enough; I create a Texture, load a .png file to it, then .setTexture it to a sprite object. I did this all in one method. Next, I try to use the aforementioned Sprite in another method, to be drawn to a window. It doesn't display.

Then I'm all like WTF and go crazy trying to fix it, then I end up putting it in the method that draws to the RenderWindow and it works fine. Why be this?

#include <iostream>

#include "Engine.h"

Engine::Engine()
{
   
}

Engine::~Engine()
{
    delete window;
}

bool Engine::Initialize()
{
    window = new sf::RenderWindow(sf::VideoMode(800, 612, 32), "BattleGame - V2");
   
    if(!window)
        return false;
    else
        return true;
   
    // Let's create the background image here, where everything initializes.
    if(!BackgroundTexture.loadFromFile("BattleGame.app/Contents/Resources/BG.png"))
        throw "Failure!";
    else
        Background.setTexture(BackgroundTexture);
}

void Engine::ProcessInput()
{
    sf::Event Event;
   
    while(window->pollEvent(Event))
    {
        switch(Event.type)
        {
            case sf::Event::Closed:
                window->close();
                break;
        }
    }
}

void Engine::MainLoop()
{
    while(window->isOpen())
    {
        ProcessInput();
        Update();
        RenderFrame();
    }
}

void Engine::Update()
{
   
}

void Engine::RenderFrame()
{
    window->clear();
    window->draw(Background); // And now we draw the background; but it doesn't work.
    window->display();
}

void Engine::Go()
{
    if(!Initialize())
        throw "The engine failed to initialize.";
    else
        MainLoop();
}
 

Pages: [1]