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

Pages: [1]
1
Graphics / Re: STL map RenderTexture don't seem to be behaving
« on: January 06, 2014, 01:01:44 am »
Nexus, you're the best.

2
Graphics / Re: STL map RenderTexture don't seem to be behaving
« on: January 05, 2014, 03:04:04 pm »
By inheriting sf::RenderTexture for a scene, I'm given all the nice methods to automatically draw and receive events from the RenderWindow. However, I'm up for any alternatives. What do you suggest I do?

3
Graphics / Re: STL map RenderTexture don't seem to be behaving
« on: January 05, 2014, 01:23:11 am »
I fixed my issue. It was because my Scene class methods weren't being overrided (not virtual), so having the map recognize them as only Scene pointers made it call a blank method. D'Oh!

4
Graphics / STL map RenderTexture don't seem to be behaving
« on: January 05, 2014, 12:52:42 am »
Hi everyone.

So here is my situation: I'm trying to implement a system that allows me to globally change through different game states, in this case, a Scene class. The Scene class inherits sf::RenderTexture so I get all the benefits of drawing and displaying sf::Sprites and such. The way I manage the Scenes is through an STL map where I would store a pointer to the Scene along with an std::string for the key. I then implemented a method called getCurrScene() where it would return a pointer to the scene by returning the item of the map with the index of the current string. The current string is set manually through a method called setCurrentString. My problem is that the pointer that seems to be returned by the STL map of Scene pointers are blank. I get no errors, but when I run  my program, I end up with a distorted window, the same window you would get if you don't update/draw to the window correctly. From testing with cout, none of the methods of the scene are being called! Any help would be appreciate.

GSWindow.cpp
#include "GSWindow.h"

GSWindow::GSWindow() : sf::RenderWindow(sf::VideoMode(600,600),"Greenberg Rocket"){
    addScene(new Menu(),"menu");
    addScene(new Game(),"game");
   
    //The current scene to be rendered to the window
    Scenes::setCurrentString("menu");
    setFramerateLimit(60);
    while(isOpen()){
        sf::Clock clock;
        sf::Event event;
        while(pollEvent(event)){
            if(event.type == sf::Event::Closed){
                close();
            }
            getCurrScene()->pollEvent(event);
            }
        clear(sf::Color(0,0,0));
        getCurrScene()->update(clock.getElapsedTime().asSeconds());

        getCurrScene()->display();
        sf::Sprite s(getCurrScene()->getTexture());
        draw(s);
        display();
    }
}

void GSWindow::addScene(Scene *s, std::string n){
    scenes[n] = s;
}

Scene* GSWindow::getCurrScene(){
   
    return scenes.find(Scenes::getCurrentString())->second;
}

int main(int argc, char* argv[]){
    new GSWindow();
    return 0;
}
 

GSWindow.h
#ifndef GS_WINDOW_H
#define GS_WINDOW_H
#include <SFML/Graphics.hpp>
#include <iostream>
#include "ResourcePath.hpp"
#include "Menu.h"
#include "Game.h"
#include "Scenes.h"
#include <map>
class GSWindow : public sf::RenderWindow {
public:
    GSWindow();
    void addScene(Scene* s, std::string n);
    Scene* getCurrScene();
private:
    std::map<std::string,Scene*> scenes;
};
#endif
 
Scene.h
#ifndef SCENE_H
#define SCENE_H
#include <SFML/Graphics.hpp>
#include "SpriteTween.h"
#include <vector>
class Scene : public sf::RenderTexture {
public:
    Scene();
    void update(float time) {};
    void pollEvent(sf::Event& event) {};

};

#endif
 

Pages: [1]
anything