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

Pages: [1]
1
General / Re: 2D RPG
« on: January 25, 2014, 11:30:30 pm »
I wanted to expand my programm to implement your code, but an error appeared..

Error(translation):
Quote
1>------ Constructing started: Project: 2D RPG, Configuration: Debug Win32 ------
1>The building process was started 25.01.2014 23:07:11.
1>InitializeBuildStatus:
1>  Updating the timestamp of "Debug\2D RPG.unsuccessfulbuild".
1>ClCompile:
1>  menu.cpp
1>c:\sfml\include\sfml\window\window.hpp(477): error C2248: "sf::NonCopyable::operator =": No access to private members, which declaration is done in sf::NonCopyable-Class.
1>          c:\sfml\include\sfml\system\noncopyable.hpp(79): See declaration of 'sf::NonCopyable::operator ='
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42): See declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function "sf::Window &sf::Window::operator =(const sf::Window &)".
1>c:\sfml\include\sfml\graphics\rendertarget.hpp(419): error C2248: "sf::NonCopyable::operator =": No access to private members, which declaration is done in sf::NonCopyable-Class.
1>          c:\sfml\include\sfml\system\noncopyable.hpp(79): See declaration of 'sf::NonCopyable::operator ='
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42): See declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function "sf::RenderTarget &sf::RenderTarget::operator =(const sf::RenderTarget &)".
1>  gui.cpp
1>c:\sfml\include\sfml\window\window.hpp(477): error C2248: "sf::NonCopyable::operator =": No access to private members, which declaration is done in sf::NonCopyable-Class.
1>          c:\sfml\include\sfml\system\noncopyable.hpp(79): See declaration of 'sf::NonCopyable::operator ='
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42): See declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function "sf::Window &sf::Window::operator =(const sf::Window &)".
1>c:\sfml\include\sfml\graphics\rendertarget.hpp(419): error C2248: "sf::NonCopyable::operator =": No access to private members, which declaration is done in sf::NonCopyable-Class.
1>          c:\sfml\include\sfml\system\noncopyable.hpp(79): See declaration of 'sf::NonCopyable::operator ='
1>          c:\sfml\include\sfml\system\noncopyable.hpp(42): See declaration of 'sf::NonCopyable'
1>          This diagnostic occurred in the compiler generated function "sf::RenderTarget &sf::RenderTarget::operator =(const sf::RenderTarget &)".
1>  button.cpp
1>  Code is generated...
1>
1>Failed to create
1>
1>Elapsed time 00:00:01.93
========== Create: 0 successful, Skipped error at 1, 0 current, 0 skipped ==========

gui.h
//==========================================================//
// CLASS: GUI                                               //
// DESC: Manages GUI                                        //
//==========================================================//
#ifndef __GUI_H__
#define __GUI_H__

//=================================
// included dependencies
#include "menu.h"
#include <SFML/Graphics.hpp>

//=================================
// class
class GUI
{
public:
        GUI();                                                  // Constructor
        ~GUI();                                                 // Destructor

        sf::RenderWindow window;                // Needed to display graphics

        enum menus { main, game, options, credits };            // Enum of menus

        void Initialize(sf::RenderWindow _window);                      // Initialize
        void LoadContent();                                                                     // Loading the needed content
        void UnloadContent();                                                           // Unload all content
        void Update(sf::Time elapsedTime, sf::Event event);     // Check Events
        void Draw(sf::Time elapsedTime);                                        // Redraw screen
};

#endif // __GUI_H__
 

gui.cpp
#include "gui.h"

GUI::GUI()
{
       
}

GUI::~GUI()
{

}

void GUI::Initialize(sf::RenderWindow _window)
{
        window = _window;
}

void GUI::LoadContent()
{
       
}

void GUI::UnloadContent()
{

}

void GUI::Update(sf::Time elapsedTime, sf::Event event)
{
       
}

void GUI::Draw(sf::Time elapsedTime)
{
        window.clear();



        window.display();
}
 

menu.h
//==========================================================//
// CLASS: MENU                                              //
// DESC: Menu prototype                                     //
//==========================================================//
#ifndef __MENU_H__
#define __MENU_H__

//=================================
// included dependencies
#include <SFML/Graphics.hpp>

//=================================
// class
class Menu
{
public:
        Menu();                                                 // Constructor
        ~Menu();                                                // Destructor

        sf::RenderWindow window;                // Needed to display graphics

        void Initialize(sf::RenderWindow _window);                      // Initialize
        void LoadContent();                                                                     // Loading the needed content
        void UnloadContent();                                                           // Unload all content
        void Update(sf::Time elapsedTime, sf::Event event);     // Check Events
        void Draw(sf::Time elapsedTime);                                        // Redraw screen
};

#endif // __MENU_H__
 

menu.cpp
#include "menu.h"

Menu::Menu()
{
       
}

Menu::~Menu()
{

}

void Menu::Initialize(sf::RenderWindow _window)
{
        window = _window;
}

void Menu::LoadContent()
{
       
}

void Menu::UnloadContent()
{

}

void Menu::Update(sf::Time elapsedTime, sf::Event event)
{
       
}

void Menu::Draw(sf::Time elapsedTime)
{
       
}
 

element.h
//==========================================================//
// CLASS: ELEMENT                                           //
// DESC: Base class for all UI Elements (e.g. Button)       //
//==========================================================//
#ifndef __ELEMENT_H__
#define __ELEMENT_H__

//=================================
// included dependencies
#include <SFML/Graphics.hpp>

//=================================
// class
class Element
{
public:
        sf::RenderWindow window;                // Needed to display graphics

        virtual void Initialize(sf::RenderWindow _window);                                                                      // Initialize
        virtual void LoadContent();                                                                     // Loading the needed content
        virtual void UnloadContent();                                                           // Unload all content
        virtual void Update(sf::Time elapsedTime, sf::Event event);     // Check Events
        virtual void Draw(sf::Time elapsedTime);                                        // Redraw screen
};

#endif // __ELEMENT_H__
 

button.h
//==========================================================//
// CLASS: GUI                                               //
// DESC: Manages GUI                                        //
//==========================================================//
#ifndef __BUTTON_H__
#define __BUTTON_H__

//=================================
// included dependencies
#include "element.h"

//=================================
// class
class Button : public Element
{
public:
        Button();                                                       // Constructor
        ~Button();                                                      // Destructor

        void Initialize();                                                                      // Initialize
        void LoadContent();                                                                     // Loading the needed content
        void UnloadContent();                                                           // Unload all content
        void Update(sf::Time elapsedTime, sf::Event event);     // Check Events
        void Draw(sf::Time elapsedTime);                                        // Redraw screen

private:
       
};

#endif // __BUTTON_H__
 

button.cpp
#include "button.h"

Button::Button()
{
       
}

Button::~Button()
{

}

void Button::Initialize()
{
       
}

void Button::LoadContent()
{
       
}

void Button::UnloadContent()
{

}

void Button::Update(sf::Time elapsedTime, sf::Event event)
{
       
}

void Button::Draw(sf::Time elapsedTime)
{
       
}
 

2
General / Re: 2D RPG
« on: January 25, 2014, 06:07:20 pm »
I've removed the pointer..
After these changes the programm still need constantly 33% of my CPU?!
And sometimes, instead of making big jumps like before, it still scrolls faster?!

3
General / Re: 2D RPG
« on: January 25, 2014, 05:48:26 pm »
That's very strange. Are you sure you're doing this?:
Didn't work(German translation):
Quote
InelliSense: No "="-Operator is matching this operand.

You need to put your files in %Documents%\Visual Studio 2010\Projects\[Project name]\[Project name] to use relative paths in Visual Studio (you can also set the working directory in your project settings under Debugging->Working Directory, but this is the default one).

I changed it to the follwing and it works :D
Quote
texture.loadFromFile("data\\rpg.jpg");

4
General / Re: 2D RPG
« on: January 25, 2014, 05:42:34 pm »
I've now set VSync(true) and removed the couts.
Now I have a constant framerate and it works without laggs.

I still have another question:
I want to build my RPG out of many rectangles and I will save them in a 2D Array.
How should I structure the data in the file? And which file format would you recommend me to use?

Another problem is that I want to expand and update the Map sometimes.
So if I save the users last position, how can I place his character on the same position after the map update?

The best solution would be to just use tilemaps of maybe 255x255 rectangles and a 4D Array.
The first two dimension would specify the position of the tilemap and the second two the content of the tilemap.

Also each rectangle should be filled with a sprite for the surface.
So should I just use an Array of Sprites and use a switch case to load the textures into each rectangle(sprite)?

There also must be a value for each rectangle whether clipping is enables for it or not.
I also need to save the height because I have at least 2 terrain levels.
The ground and objects that shoud be drawn over it, like houses, trees etc.

Has anyone a better idea how to do this?

5
General / Re: 2D RPG
« on: January 25, 2014, 05:14:32 pm »
Some things that might cause lag is that you're calling setView every frame, I'm not too familiar with views but I don't think you need to do that.
I need to update the View because it may change every frame if you press a key..

Why is your instance of Game a pointer? Just create it on the stack, it'll delete itself and it's much safer.
Id didn't programm for a long time and if don't use a pointer it throws errors..

Don't use absolute paths for filenames unless you want the game for yourself only. Use a relative path.
I know. But if I don't use an absolute path in this case he is "unable to open file".
I don't know why but if I put the project in another folder it works.
But Visual Studio compiles to %Documents%\Visual Studio 2010\Projects\[Project name]
and I want my projects there.
It also works if I manually start the exe file with admin permissions.

6
General / Re: 2D RPG
« on: January 25, 2014, 03:33:40 pm »
main.cpp
Quote
#include "game.h"

int main()
{
    Game *game = new Game();
   sf::Clock clock;

   game->LoadContent();

   // Gameloop
    while (game->window.isOpen())
    {
      sf::Time elapsed = clock.restart();

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

         game->Update(elapsed, event);
        }

      game->Draw(elapsed);
    }

   game->UnloadContent();

   delete(game);

    return 0;
}

game.h
Quote
//==========================================================//
// CLASS: Game                                              //
// DESC: Used to manage gameloop in different procedures    //
//==========================================================//
#ifndef __GAME_H__
#define __GAME_H__

//=================================
// included dependencies
#include <iostream>
#include <SFML/Graphics.hpp>

//=================================
// class
class Game
{
public:
   sf::RenderWindow window;      // Needed to display Window

   Game();                     // Constructor
   ~Game();                  // Destructor

   void Initialize();                           // Initialize game
   void LoadContent();                           // Loading the needed content
   void UnloadContent();                        // Unload all content
   void Update(sf::Time elapsedTime, sf::Event event);   // Check Events
   void Draw(sf::Time elapsedTime);               // Redraw screen

private:
   /* JUST TEST!! REMOVE!! */
   sf::Texture texture;
   sf::Sprite sprite;
   sf::View view;
   float view_left;
   float view_top;
   float view_width;
   float view_height;
};

#endif // __GAME_H__

game.cpp
Quote
#include "game.h"

Game::Game()
{
   Game::Initialize(); // Initialize game when class is created
}

Game::~Game()
{

}

void Game::Initialize()
{
   window.create(sf::VideoMode(800, 600), "2D RGP");

   view_left = 200;
   view_top = 200;
   view_width = 200;
   view_height = 200;
}

void Game::LoadContent()
{
   texture.loadFromFile("C:\\Users\\alexander\\Documents\\Visual Studio 2010\\Projects\\2D RPG\\Debug\\data\\rpg.jpg");
   sprite.setTexture(texture);

   view.reset(sf::FloatRect(view_left, view_top, view_width, view_height));
}

void Game::UnloadContent()
{

}

void Game::Update(sf::Time elapsedTime, sf::Event event)
{
   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
   {
      view_left -= 0.1 * elapsedTime.asMicroseconds();
      std::cout << "Left, " << view_left << std::endl;
   }

   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
   {
      view_left += 0.1 * elapsedTime.asMicroseconds();
      std::cout << "Right, " << view_left << std::endl;
   }

   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
   {
      view_top -= 0.1 * elapsedTime.asMicroseconds();
      std::cout << "Up, " << view_top << std::endl;
   }

   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
   {
      view_top += 0.1 * elapsedTime.asMicroseconds();
      std::cout << "Down, " << view_top << std::endl;
   }


   if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageUp))
   {
      view_width -= 0.1 * elapsedTime.asMicroseconds();
      view_height -= 0.1 * elapsedTime.asMicroseconds();

      std::cout << "Zoom in, " << view_width << std::endl;
   }

   if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageDown))
   {
      view_width += 0.1 * elapsedTime.asMicroseconds();
      view_height += 0.1 * elapsedTime.asMicroseconds();

      std::cout << "Zoom out, " << view_width << std::endl;
   }
}

void Game::Draw(sf::Time elapsedTime)
{
   window.clear();

   view.reset(sf::FloatRect(view_left, view_top, view_width, view_height));

   window.setView(view);
   window.draw(sprite);

   window.display();
}

7
General / 2D RPG
« on: January 25, 2014, 02:59:05 pm »
I'm trying to develope a little RPG with a friend.
The first thing I did was displaying a view, creting a view and make it movable with keyboard.
I'm using this Code to move the view:
Quote
f (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
   {
      view_left -= 0.1 * elapsedTime.asMicroseconds();
      std::cout << "Left, " << view_left << std::endl;
   }

Then I use this Code to update the window:
Quote
view.reset(sf::FloatRect(view_left, view_top, view_width, view_height));

   window.setView(view);
   window.draw(sprite);

The problem is that the programm sometimes has laggs.
For example the value, which I also display in my console when changed, increases by 20-30 every time.
But sometimes it also increases by 200 and more..

Another problem is the performance.
I have six-core 4,2 Ghz CPU and if I start the programm my CPU usage increses to 50 up to 70%  :o

I only have the view and 1 image which I display and move..

8
My Project is in the default Path..
C:\Users\akaras\Documents\Visual Studio 2013\Projects
And it is not set to read-only.. I already checked that..
I want to distribute this programm on my website, so it needs to work without administrator permission..

9
General / Programm could only load image with administrator permission
« on: October 26, 2013, 06:38:27 pm »
Hi,
When I load an image by using "loadFromFile("file.jpg")" the programm outputs to the console:
Quote
Failed to load image "image.jpg". Reason : Unable to open file
When I first compile the programm and then start it manually with administrator permissions it works perfectly.
The image and the executable are in the same directory which is not protected..

So is there a way to either do it without administrator permissions or how can I let VS2013 directly start the compiled exe with permission..

10
General / Re: Visual Studio 2013 - MSVCR110D.dll missing
« on: October 26, 2013, 06:22:17 pm »
I compiled SFML with VS2013 and now it works :D
Thanks for your help :)

11
General / Re: Visual Studio 2013 - MSVCR110D.dll missing
« on: October 25, 2013, 08:56:03 pm »
Could you please post a link to the VS 2012 download?
Because I already searched for it...

I thought they only bring out a new Version of VS every two years..

12
General / Visual Studio 2013 - MSVCR110D.dll missing
« on: October 25, 2013, 04:49:15 pm »
Hi,
I were not able to find a download for Visual Studio 2012 so I downloaded Visual Studio 2013..
First I wanted to try if everything works because SFML is only available for VS 2012 and not 2013..
So I followed the tutorial for SFML 2.1 and as I debugged an error occured:
Quote
The program could not be started because MSVCR110D.dll is missing on your computer. [..]

This is maybe not the original error message. I am from Germany and use the german version of VS, so I translated it. But I think it is comprehensible ;)

Pages: [1]