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.


Topics - natchos

Pages: [1] 2
1
Audio / sf::Sound derivative not playing
« on: May 19, 2014, 07:21:16 pm »
I am trying to make an sound manager, from where I can play sounds through a system of IDs, for this I created a child class(Called ironically Sound_Struct). The problem I'm running into is that the sound I have loaded into it doesn't play. I have checked the file itself(through use of sf::Sound), aswell as the sf::SoundBuffer vector where I load/store the buffers. Here is the code, if someone could help that would be wonderful.

SoundManager.hpp
#pragma once
#include <SFML\Audio.hpp>
#include <list>
#include <string>
#include <iomanip>

class Sound_Struct : public sf::Sound
{
public:
        Sound_Struct(sf::SoundBuffer S_BUFF_SRC, std::string n_designation, int n_id);
        Sound_Struct(std::string n_designation, int n_id);
        void set_ID(int n_id){this->m_id = n_id;}
        int get_ID(){return this->m_id;}
        void set_Name(std::string n_designation){this->m_designation = n_designation;}
        std::string get_Name(){return this->m_designation;}
private:
        std::string m_designation;
        int m_id;
};

struct Music_Struct : public sf::Music
{
public:
        Music_Struct(std::string m_filename, std::string n_designation, int n_id);
        void set_ID(int n_id){this->m_id = n_id;}
        int get_ID(){return this->m_id;}
        void set_Name(std::string n_designation){this->m_designation = n_designation;}
        std::string get_Name(){return this->m_designation;}
private:
        std::string m_designation;
        int m_id;
};
class Sound_Manager
{
public:

        Sound_Manager();
        bool Add_Sound_Buffer(std::string m_filename); //Adds an sound_buffer into the Sound_Buffer list. Used for initial setup.

        bool Add_Sound(std::string m_filename, std::string m_designation, int m_id);
        void Add_Sound(sf::SoundBuffer m_S_BUFF, std::string m_designation, int m_id);
        void Add_Sound(sf::Sound* m_Sound, std::string m_designation, int m_id);
        void Add_Sound(int S_BUFF_ID, std::string m_designation, int m_id);
        void Add_Music(std::string m_filename, std::string m_designation, int m_id);
        void Delete_Sound(int m_id);
        void Delete_Sound(std::string m_designation);

        sf::SoundBuffer getBuffer(int ID);

        void Play_Sound(std::string m_designation);
        void Play_Sound(int m_id);
        void Play_Music(std::string m_designation);
        void Play_Music(int m_id);
        void Pause_All();
        void Resume_Previous();

        int no_Of_Sounds()
        {
                return this->Sounds.size();
        };
        int no_Of_Buffers()
        {
                return this->Sound_Buffers.size();
        };
public:
        std::list<Sound_Struct> Sounds; //Since sounds are given unique IDs, and likely change during runtime these are placed in a list
        std::vector<sf::SoundBuffer> Sound_Buffers; //Unchanging after startup, so placed in a vector
        std::vector<Music_Struct*> Songs; //Unchanging after startup, so placed in a vector
};

SoundManager.cpp (only including the functions that are relevant)
Sound_Struct::Sound_Struct(sf::SoundBuffer S_BUFF_SRC, std::string n_designation, int n_id) : sf::Sound(S_BUFF_SRC)
{
        this->m_designation = n_designation;
        this->m_id = n_id;
}
Sound_Manager::Sound_Manager()
{
        this->Songs.clear();
        this->Sounds.clear();
        this->Sound_Buffers.clear();
}
bool Sound_Manager::Add_Sound_Buffer(std::string m_filename)
{
        sf::SoundBuffer S_BUFF;
        if(S_BUFF.loadFromFile(m_filename))
        {
                this->Sound_Buffers.push_back(S_BUFF);
                return true;
        }
        else
                return false;
}
bool Sound_Manager::Add_Sound(std::string m_filename, std::string m_designation, int m_id)
{
        sf::SoundBuffer S_BUFF;
        if(S_BUFF.loadFromFile(m_filename))
        {
                this->Sound_Buffers.push_back(S_BUFF);
                Sound_Struct ne_Sound(S_BUFF,m_designation,m_id);
                this->Sounds.push_back(ne_Sound);
                return true;
        }
        else
                return false;
}
void Sound_Manager::Add_Sound(sf::SoundBuffer m_S_BUFF, std::string m_designation, int m_id)
{
        this->Sound_Buffers.push_back(m_S_BUFF);
        Sound_Struct ne_Sound(m_S_BUFF, m_designation, m_id);
        this->Sounds.push_back(ne_Sound);
}
void Sound_Manager::Play_Sound(std::string m_designation)
{
        std::list<Sound_Struct>::iterator iter;
        for(iter = this->Sounds.begin(); iter != this->Sounds.end(); iter++)
        {
                if(iter->get_Name() == m_designation)
                        iter->play();
        }
}
void Sound_Manager::Play_Sound(int m_id)
{
        std::list<Sound_Struct>::iterator iter;
        for(iter = this->Sounds.begin(); iter != this->Sounds.end(); iter++)
        {
                if(iter->get_ID() == m_id)
                        iter->play();
        }
}

The actual loading/playing is done in the main file

        if(!Miss_Lisa.Add_Sound_Buffer("Sounds/Laser_Shot.wav"))
        {
                return;
        }
        Miss_Lisa.Add_Sound(0,"Laser_Shot",1);
//The sound can now be played by calling
Miss_Lisa.play_Sound(1)

2
Graphics / [Solved]Colouring coloured tiles using sf:color
« on: March 09, 2014, 08:25:16 pm »
In my current project I have tiles which represent a certain type of terrain. Each of these types have their own coloured tile image. This all works very well but I also want to be able to represent a water/water depth value on top of a tile if there is water.
I would like to colour the tiles as they are outputted by setting the tiles color with a sf::color value where an higher water depth would mean an stronger blue.

I am currently using the following code:
        if(Displayed_Tiles[x][y].is_Water())
                        {
                                Rendering_Tiles[x][y].setColor(sf::Color(125,125,255/(Displayed_Tiles[x][y].Get_Water_Saturation()),255/2));
                        }

Where Displayed_Tiles
  • [y].Get_Water_Saturation() is an number over 1 which goes down lower as the water depth increases.  This code is called each time I draw the tiles to the screens. After the tiles have been draw I "flash" all Rendering_Tiles which means I reset their colour.

The problem is that it doesn't work, in two ways. The tiles aren't colored blue, no matter the water depth and the tiles color does not change if their water depth is decreased/increased.
Anyone have any clue of why the code isn't working or what steps I should take to remedy it?(Or recommend me a better system to colour the tiles according to a water depth variable?).

Sorry if an topic similar to this has been posted. Searched around on the graphics and general boards but couldn't find anything relevant to this topic.

3
General / LNK 1112 compiling SFML 2.0 to VS2012
« on: January 31, 2013, 10:03:18 pm »
So I'm trying to convert a project of mine from vc++2008 to vs2012, and discovered that since there are no ready built version of SFML for it I would have to compile it myself from CMake.

Firstly I would just like to say that I have never used CMake and I apologize in advance since the solution will most likely be obvious to veterans of CMake.
I followed the tutorial at
http://sfml-dev.org/tutorials/2.0/compile-with-cmake.php
I built the static libraries, with Visual Studio 11(not x64!) chosen as my generator in CMake.

After linking everything correctly(I think) I attempted to compile. I got a few errors which I corrected.
However during linking I get LNK1112 error, with the output saying:
error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'       C:\Users\Admin\Google Drive\C++ project\VS2012\New Game\sfml-system-s-d.lib(Time.obj)  
 

So I was wondering how I should fix this. Did I set something wrong in the CMake options, or is something else the cause?

Some general info:
  • I am using CMake 2.8.10
  • I am using Visual Studio 2012 Express
  • The project itself was win32 in my vc++2008 configuration

4
General / SF::Rotation returning a value above 360 or below 0
« on: November 10, 2012, 12:41:18 am »
So, the title says it all. Despite the description text of sf::transformables function sf::getrotation says:

get the orientation of the object

The rotation is always in the range [0, 360].
Returns:
Current rotation, in degrees

So is this untrue or not? To see the rotation I'm using
                                       
std::ostringstream ss;
ss.str("");
ss << player.getRotation();
VelocityText.setString(sf::String(ss.str()));
and then drawing VelocityText to the screen.

5
General / Mouse input
« on: October 23, 2012, 09:15:07 am »
Hey I was wondering whether there is something wrong with the SFML mouse input class.
When I get input from the keyboard I use a pollEvent and a switch type structure

while(App.pollEvent(Event))
{
        switch(Event.type)
        {
                case sf::Event::Closed:
                        App.close();
                        break;
                case sf::Event::KeyPressed:
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        {
                                //Do stuff
                        }
                        break;
        }
}

And it works fine.

However attempting to put in a
case sf::Event::MouseButtonPressed: doesn't work.
In my application I did it like this

while(App.pollEvent(Event))
{
        switch(Event.type)
        {
                case sf::Event::Closed:
                        App.close();
                        break;
                case sf::Event::KeyPressed:
                        if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
                        {
                                //Do stuff
                        }
                        break;
                case sf::Event::MouseButtonPressed:
                        if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
                        {
                                //Do stuff
                        }
        }
}

But it never triggered/worked. Instead I had to do this:

while(App.pollEvent(Event))
{
        switch(Event.type)
        {
                //Process events
        }
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
        //React to the mouse button
}
Am I doing an incorrect implementation or is it something else?

6
Graphics / Using an untextured or filled shape
« on: October 15, 2012, 11:33:01 am »
Is there any way to, instead of using sf::texture object to create and use a sf::shape, to simply fill the shape with a specified colour and then drawing it to the screen.

Alternatively can you fill a texture object with a single colour instead of loading an image?

7
General / Having one calculation loop and one graphic loop in SFML 2.0
« on: October 10, 2012, 03:02:06 pm »
To explain my topic a bit better: Is there anyway to have a section of code which goes much faster than the rest of SFML?
I would like to change my project to have two loops: one drawing loop which is "only" called 40 times per second, so that the visual portion of the game has 40 fps, and a update/calculation loop which runs at a higher speed (say 70-80 times per second).

Is there any easy way to do this, is it impossible with sfml or is it possible but I just have to code it myself?

8
General / SFML 2.0 switching from debug to release setting
« on: September 22, 2012, 12:03:44 am »
So, I've made the rough beginnings of the seed of a small demo of a game that I'm working on and now I would like to send it to one of my friend.

However, when I try to compile it in release setting an error message pops up saying that I'm missing sfml-system-2.dll.

Is this a known problem or is it something trivial that I have done wrong? I don't think that there is anything wrong in the code itself since it compiles and runs just fine in debug setting. Also I checked in the sfml 2.0-rc folder and found that there was a file called sfml-system-2.dll lying in /bin. So the file is there my comp/compiler just wont find it.

Any tips?

FYI I'm using visual c++ express 2008

9
Feature requests / sf::Text constructor
« on: September 04, 2012, 09:08:34 am »
I was just wondering whether it was possible to get a sf::Text constructor which does not require a string upon creation, or could you perhaps have the sf::string& string, changed to a default empty parameter(so that it would be the programmers choice if he want's to initialize a sf::text object with a string).

10
General / [SFML 2.0] Access violation (debugging)
« on: September 03, 2012, 09:40:00 pm »
So, I recently switched from sfml 1.6 to sfml 2.0.
Now I get this error

Unhandled exception at 0x55520481 in New Game.exe: 0xC0000005: Access violation reading location 0x00000008.

However I only get it upon exiting/shutting down the program. Normally the compiler would attempt to point me in the direction of the transgressive code, but after the first error message I get this:

There is no source code available for the current location.

and an option to show disassembly.

I am very sorry to say that I can make neither head nor tails of disassembly code.
Does anyone have any tips/solutions or a good way to try debugging this?

11
General / sfml 1.6 sprite::GetSize equivalent? and general 2.0 questions
« on: August 17, 2012, 12:00:09 am »
So I'm back with another fairly stupid question :P

Is there a 2.0 equivalent to 1.6 sprite::GetSize() function, or is getGlobalBounds() the closest thing to that that we get?

I'm just wondering because I am in the middle of changing my project from 1.6 to 2.0, so I would just like to know, since it would change the structure of some crucial functions.(Not in a bad way, I just wonder whether I have to rewrite them :P)

12
General / If bug? SFML 1.6
« on: July 21, 2012, 03:32:20 am »
Hey so I've got this really weird expression that just flatout refuses to evaluate to true.

Here comes the function dump, which I will explain.

bool ADVBoxCollision(sf::gEntity& player, sf::gEntity& sprite2, bool& pTop,bool& pLSide, bool& pRSide, bool& pBottom)
{
        float YVel = player.GetYVelocity();
        float HSLS = 0;
        if((YVel > -3.0f) && (YVel < 3.0f)) HSLS = 7;
        else if((YVel > -9.0f) && (YVel < 9.0f)) HSLS = 30;
        else HSLS = 50;
        /* HSLS stands for HighSpeed-LowSpeed. If the speed of one of the objects is high it is generally preferable to use a larger hitbox (to more accurately
        detect hits. However, at low speeds this results in alot of jitter as the sprites get pushed around the whole time. Therefore we modify the HSLS
        variable depending on the Velocity given to us */

        bool Firsttotheleft = false;
        bool Firsttotheright = false;
        bool Firstabove = false;
        bool Firstbelow = false;
        sf::FloatRect FirstRect = sf::FloatRect(player.GetPosition().x - player.GetSize().x/2 - HSLS, player.GetPosition().y - player.GetSize().y/2 - HSLS,player.GetPosition().x + player.GetSize().x/2 + HSLS,player.GetPosition().y+player.GetSize().y/2+HSLS);
        sf::FloatRect SecondRect = sf::FloatRect(sprite2.GetPosition().x - sprite2.GetSize().x/2, sprite2.GetPosition().y - sprite2.GetSize().y/2,sprite2.GetPosition().x + sprite2.GetSize().x/2 ,sprite2.GetPosition().y+sprite2.GetSize().y/2);
        //ToS stands for Top or side. It tells whether the sprite collided with the top/bottom part or the side part. 0 = top/bottom, 1 = sides
        if(BoxCollision(FirstRect, SecondRect))
        {
                if((FirstRect.Left - 30) <= (SecondRect.Right - (FirstRect.GetWidth() - HSLS*2)) &&  (FirstRect.Left + 10 >= (SecondRect.Right - FirstRect.GetWidth())))
                        Firsttotheleft = true;
                if((FirstRect.Right + 30) >= (SecondRect.Left + (FirstRect.GetWidth() - HSLS*2)))
                        Firsttotheright = true;
                if((FirstRect.Top - 30) <= (SecondRect.Bottom - (FirstRect.GetHeight() - HSLS*2)))
                        Firstabove = true;
                if((FirstRect.Bottom + 30) >= (SecondRect.Top + (FirstRect.GetHeight() - HSLS*2)))
                        Firstbelow = true;
                if(Firstbelow) pBottom = true;
                if(Firstabove) pTop = true;
                if(Firsttotheright) pRSide = true;
                if(Firsttotheleft) pLSide = true;
                return BoxCollision(FirstRect, SecondRect);
        }
        else return false;
}

Most of it is fairly straightforward. I construct two rectangles from the sprite and then collide them.
The problem comes when I need to find a distinction between the sides( the
if((FirstRect.Left - 30) <= (SecondRect.Right - (FirstRect.GetWidth() - HSLS*2)) &&  (FirstRect.Left + 10 >= (SecondRect.Right - FirstRect.GetWidth())))
                        Firsttotheleft = true;
                if((FirstRect.Right + 30) >= (SecondRect.Left + (FirstRect.GetWidth() - HSLS*2)))
                        Firsttotheright = true;
                if((FirstRect.Top - 30) <= (SecondRect.Bottom - (FirstRect.GetHeight() - HSLS*2)))
                        Firstabove = true;
                if((FirstRect.Bottom + 30) >= (SecondRect.Top + (FirstRect.GetHeight() - HSLS*2)))
                        Firstbelow = true;
part)

It just flat out refuses to evaluate to true,
I've tried changing the if expressions to every goddamn combination possible.
At one point I simply wrote it as
if((FirstRect.Left > 0)
                        Firsttotheleft = true;
                if((FirstRect.Right > 0)
                        Firsttotheright = true;
                if((FirstRect.Top > 0)
                        Firstabove = true;
                if((FirstRect.Bottom > 0)
                        Firstbelow = true;
Not even then did the ifs evaluate to true (and before you ask, yes I put in breakpoints to find if FirstRect was null or set to zero. It was not).

I'm just wondering whether anyone else has encountered something similar.

13
General / [Solved]Weird graphical bug
« on: June 19, 2012, 03:26:09 pm »
Hello. So I think I've fucked up pretty big time.
Apparently some coding I did broke something either in vs2008 or in one of the includes needed.

To give some background; I was coding to make a enemy turn to face me in 2d, and I wanted to use the sf::sprite::FlipX function. However I soon ran into a problem, namely that I could not, with any ease, check whether it had been flipped.

I decided to do some modifying to the SFML source code(not a good idea I know) to make the myIsFlippedX and myIsFlippedY variable of sf::sprite not private, but instead protected (since I have a class that inherits from sf::sprite I could then put in a IsFlipped function as a class member).

So basically I changed this

00154 protected :
00155
00160     virtual void Render(RenderTarget& Target) const;
00161
00162 private :
00163
00165     // Member data
00167     ResourcePtr<Image> myImage;      
00168     IntRect            mySubRect;    
00169     bool               myIsFlippedX;
00170     bool               myIsFlippedY;

Into this:

00154 protected :
00155
00160     virtual void Render(RenderTarget& Target) const;
00161     bool               myIsFlippedY;
               bool               myIsFlippedX;
00162 private :
00163
00165     // Member data
00167     ResourcePtr<Image> myImage;      
00168     IntRect            mySubRect;      

(the code is taken from the website documentation).

The problem is that when I did that, well the game looked really weird (check out the screenshot).
Furthermore, even after I changed back the code, and even removed the SFML1.6 folder and put in a new one the issue still appears.

I have only one clue. When I first recompiled after the inital, succesful but bugged out run, VS2008 gave me an error link to a file called xtree. Something about nodes and roots. Can't seem to find the file now tho.
From what I've read about it xtree might have something to do with vectors, which I use vigourously in my work.

Anyone got any clues on how to fix this?
If anyone needs the code for figuring it out, send me a pm and I'll send it over!

PS: I also posted a non-bugged screenshot, taken from a week-old release build.
PSS: Crap, just remembered that this should probabky have been in the Graphical help section T_T

[attachment deleted by admin]

14
General / 2d tile system using 2d std::vectors.
« on: May 25, 2012, 11:35:56 am »
Hello everyone, I'm back and once again I need help from the wise persons on this forum. More specifically I need help with getting my 2d tiling system working.

I've been trying to use a 2d vector, but this stuff is fiendishly hard. I'm currently loading info from a txt file which i then put into a struct called Level which contains the type, length and height of the level. Then I try to put this info into a 2d vector, which I will then use to render.

Right now I'm am running into problem when resizing, and assigning values to the different elements of the vectors. The reason I am using a vector is that in the future I will most likely need to add more complicated backgrounds (as opposed to right now where I assume that every tile will use the same image).

Here is the code that I think is relevant.

Vector Dec
std::vector< std::vector <sf::Sprite> > BackGround(4, std::vector<sf::Sprite>(4,0));
std::vector< std::vector <sf::Sprite> >& BGPTR = BackGround;

Level LoadLevelFromTxt()
{
        int length,height,bg;
        std::ifstream FileStream("Levels.txt");
        if (FileStream.is_open())
        {
                if( FileStream.good())
                {
                        FileStream >> length;
                        FileStream >> height;
                        FileStream >> bg;
                }
                FileStream.close();
        }
        Level TheLocalLevel(length,height,(LevelType)bg);
        return TheLocalLevel;
}

void CreateBackground(Level& theLevel, std::vector<std::vector<sf::Sprite> >& BackgroundVector)
{
        BackgroundVector.resize(theLevel.Height);
        for (int i = 0; i < theLevel.Height; i++)
        {
                BackgroundVector[i].resize(theLevel.Length);
        }
        std::vector<std::vector<sf::Sprite> >::iterator iter;
        std::vector<std::vector<sf::Sprite> >::iterator itertwo;
        iter = BackgroundVector.begin();
        itertwo = BackgroundVector.at(0);
}

Currently I'm getting this error when compiling:
1>.\main.cpp(644) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' (or there is no acceptable conversion)
1>        with
1>        [
1>            _Ty=sf::Sprite
1>        ]
1>        c:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(405): could be 'std::_Vector_iterator<_Ty,_Alloc> &std::_Vector_iterator<_Ty,_Alloc>::operator =(const std::_Vector_iterator<_Ty,_Alloc> &)'
1>        with
1>        [
1>            _Ty=std::vector<sf::Sprite>,
1>            _Alloc=std::allocator<std::vector<sf::Sprite>>
1>        ]
1>        while trying to match the argument list '(std::_Vector_iterator<_Ty,_Alloc>, std::vector<_Ty>)'
1>        with
1>        [
1>            _Ty=std::vector<sf::Sprite>,
1>            _Alloc=std::allocator<std::vector<sf::Sprite>>
1>        ]
1>        and
1>        [
1>            _Ty=sf::Sprite
1>        ]

If someone could help me, I would be extremly grateful!

15
General / Linking, relative paths and sharing projects.
« on: May 04, 2012, 10:37:42 am »
So I've worked on a project and I want to send a release version to a friend so that he can see what I have done. However I don't really get how I would be able to link to SFML. I've heard of relative paths but there are no good guides about it on the internet that I could find.

The project is located in C:\Users\Olle\Desktop\C++\PAR SFML\New Game\New Game
and the sfml I want to link to is in C:\Users\Olle\Desktop\C++\PAR SFML\New Game
If I was to transfer the release folder to another computer and include a SFML-1.6\SFML in the same folder so that it would C:\Users\Something\New Game as a parent folder with two folders (SFML-1.6 and Release folders). How would I link to the SFML?

If there is anyone who can help me, alternatively provide me with a better way to organise/put together my project please do.

Sorry if the question is unclear.

Pages: [1] 2
anything