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

Pages: [1]
1
Graphics / Re: Is it possible to disable Sprite auto re-size?
« on: March 27, 2013, 11:14:12 pm »
Okay, thank you very much.

2
Graphics / Re: My small Sprite Manager
« on: March 27, 2013, 11:13:06 pm »
using new/delete is often unnecessary. Please take a look at this thread, there I mention the alternatives to manual memory management and give a lot of arguments explaining why they are better.

Would you suggest I look at Boost smart pointers? I've heard many good things about them. I'm just used to handling my pointers manually, I feel more in control.

3
Graphics / Re: My small Sprite Manager
« on: March 27, 2013, 11:06:41 pm »
I use
new
to initialize many of the objects because they must be initialized before being used. If I try to do this:

sf::Image* image;// = new sf::Image();
                if(image->LoadFromFile(file))
                        Images.insert(std::pair<std::string, sf::Image*>(file, image));

The program crashes. Also, I don't delete pointers like that because they are being added to a map. Deleting them would cause the program to crash. The destructor for SpriteManager deletes all of the pointers in the maps. The SpriteManager and RenderWindow are deleted upon program close. If you don't believe me, I can upload the project file  :P.

Quote
And choose the correct forum next time (Help/Graphics).
Sorry, I thought that since this was a discussion-type post that it would go in General.

4
Graphics / Re: My small Sprite Manager
« on: March 27, 2013, 10:27:58 pm »
Nope, I hate java actually, why do you ask? And I know 1.6 is outdated, but I'm going to keep using it for a while.

5
Graphics / My small Sprite Manager
« on: March 27, 2013, 08:28:10 pm »
I've been trying to make a lightweight template for myself using sprites and eventually physics. For now, I created this Sprite Manager:
class SpriteManager{
public:
  SpriteManager();
  ~SpriteManager();

  void         addImage(std::string file);
  sf::Image*   getImage(std::string file) { return Images.find(file)->second; }
  void         addSprite(std::string file, std::string id); // returns a pointer to created sprite
  sf::Sprite*  getSprite(std::string id)  { return Sprites.find(id)->second; };

  void update();

private:
  std::map<std::string, sf::Sprite*> Sprites; // id, sprite
  std::map<std::string, sf::Image*> Images; // file name, image
};

SpriteManager::SpriteManager(){
}

SpriteManager::~SpriteManager(){
  std::map<std::string, sf::Sprite*>::iterator it1 = Sprites.begin();
  while(it1 != Sprites.end())
    Sprites.erase(it1++);

  std::map<std::string, sf::Image*>::iterator it2 = Images.begin();
  while(it2 != Images.end())
    Images.erase(it2++);

}

void SpriteManager::addImage(std::string file){
        if(Images.find(file) == Images.end()){ // If image is not in map already.
                std::cout << "Adding image " << file << std::endl;
                sf::Image* image = new sf::Image();
                if(image->LoadFromFile(file))
                        Images.insert(std::pair<std::string, sf::Image*>(file, image));
                else
                        std::cout << "Image was unable to be loaded" << std::endl;
        }
        else{
                std::cout << "Image " << file << " was already loaded" << std::endl;
        }
}

void SpriteManager::addSprite(std::string file, std::string id){
  addImage(file);
  sf::Sprite* sprite = new sf::Sprite(*getImage(file));
  Sprites.insert(std::pair<std::string, sf::Sprite*>(id, sprite));
}

void SpriteManager::update(){
  for(std::map<std::string, sf::Sprite*>::iterator it = Sprites.begin();
      it != Sprites.end(); it++)
    g_App->Draw(*(*it).second);
}
 

This can be used by creating sprites like so:
  // Initialize the Sprite Manager
  g_SpriteManager = new SpriteManager();

  // Create the sprites
  g_SpriteManager->addImage("./res/Harlem.png");
  g_SpriteManager->addSprite("./res/Harlem.png", "Harlem");

  g_SpriteManager->addImage("./res/dot.png");
  g_SpriteManager->addSprite("./res/dot.png", "dot1");
  sf::Sprite* testSprite = g_SpriteManager->getSprite("dot1");
  testSprite->SetPosition(30.f, 53.f);

And then you call it by using:
g_SpriteManager->update();

I'd like to know what all of you think of this. Let me know if you have any critiques of my code  :D

6
Graphics / Is it possible to disable Sprite auto re-size?
« on: March 27, 2013, 08:14:46 pm »
Hello all! I am wondering if it is possible to disable the auto re-sizing of sprites upon window re-size? On a related note, would it be possible to a sprite to preserve its apparent size while using a graphics window? For instance, like how on Google maps even though you may zoom in, location markers maintain their size.

I am planning on doing a project similar to Google maps, but for one area and interactive, so that's the nature of my question. Thanks for your replies in advance!

7
General / Re: [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 11:38:05 pm »
That was it? Okay then, sorry. I think I sent it to you before I saved it, which was idiotic. Thanks for your help!

8
General / Re: [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 10:44:51 pm »
It does indeed. And SMFL_STATIC isn't linked. Here is my project folder: http://dl.dropbox.com/u/45353822/SMFL_Example.zip

Also, the SMFL folder is in Program Files(x86)/codeblocks/

9
General / Re: [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 10:09:14 pm »
I am not linking to the static libraries, and -lsfml-system is linked: https://dl.dropbox.com/u/45353822/Pics/SMFL_config.png

10
General / Re: [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 09:56:17 pm »
Okay, I have followed the tutorial for 1.6, and I'm still getting errors of the same nature:
undefined reference to `sf::Clock::Clock()'
undefined reference to `sf::Clock::GetElapsedTime() const'
and so on. I'm sure this is once again a stupid error. I opted to set it up using the second option, editing the global compiler settings. Any ideas?

11
General / Re: [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 04:40:57 pm »
Wow, my bad. Thank you for pointing out that human error! :P

12
General / [C++]Codeblocks Tutorial Compile Errors
« on: March 25, 2013, 07:07:12 am »
I just finished setting up SMFL with CodeBlocks, following this tutorial: http://www.sfml-dev.org/tutorials/2.0/start-cb.php, and linking the static libraries. I am getting the following errors when attempting to compile:
Code: [Select]
error: 'CircleShape' is not a member of 'sf'
error: expected ';' before 'shape'
error: 'shape' was not declared in this scope
error: 'class sf::RenderWindow' has no member named 'isOpen'

Along with many other errors of the same nature. It seems that there is a problem accessing the 'sf' class. I assume this is a newbie error, so sorry if I'm not doing something correctly.

I am using the C++ version 1.6 SMFL full SDK for Windows. Thanks in advance for your help!

Pages: [1]
anything