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

Pages: [1] 2 3 ... 8
1
General / Static class my map of sounds gets de-allocated
« on: March 14, 2015, 03:10:28 pm »
Hello there,

Let me first off show you my static sound manager class

header file

#pragma once

#include "SFML/Audio.hpp"
#include "Enums.h"
#include <map>
#include <vector>

static class SoundLoader
{
public:
        SoundLoader();
        ~SoundLoader();

        void LoadSounds(GameStates state);
        void PlaySound(SoundNames soundName);

        std::map<SoundNames, sf::SoundBuffer> Sounds;
        std::vector<sf::Sound> playingSounds;

        float volume;
};

Class file

#include "SoundLoader.h"

SoundLoader::SoundLoader()
{
        volume = 100;
}

SoundLoader::~SoundLoader()
{

}

void SoundLoader::LoadSounds(GameStates gameState)
{
        Sounds[SoundNames::Explosion1].loadFromFile("Assets/Sounds/Explosion1.wav");
}

void SoundLoader::PlaySound(SoundNames soundName)
{
        std::cout << std::to_string(playingSounds.size()) << std::endl;

        if (playingSounds.size() == 0)
        {
                playingSounds.push_back(sf::Sound());
                playingSounds.at(0).setVolume(volume);
                playingSounds.at(0).setBuffer(Sounds[soundName]);
                playingSounds.at(0).play();
        }
        else
        {
                int location = -1;
                for (int i = 0; i < playingSounds.size(); i++)
                {
                        if (playingSounds.at(i).getStatus() != sf::Sound::Playing && location == -1)
                        {
                                location = i;
                        }
                }

                if (location != -1)
                {
                        playingSounds.at(0).setVolume(volume);
                        playingSounds.at(location).setBuffer(Sounds[soundName]);
                        playingSounds.at(location).play();
                }
                else
                {
                        playingSounds.push_back(sf::Sound());
                        playingSounds.at(playingSounds.size() - 1).setVolume(volume);
                        playingSounds.at(playingSounds.size() - 1).setBuffer(Sounds[soundName]);
                        playingSounds.at(playingSounds.size() - 1).play();
                }

        }
}

I understand that files will of course be destroyed if they go out of scope e.g. the function is finished. but as I have a public map the sound that is loaded shouldn't be de-allocated

When I call LoadSounds() my Sounds have a soundbuffer populated. Then when I go ahead and call PlaySound with the correct enum name, I viewed my Sounds map and the size is 0, can anyone see what I am doing wrong here? Also I am declaring my soundloader like so in my header files

game.h file
SoundLoader soundLoader;

Basically I want to have only one soundLoader which my other classes can just define a static soundLoader which will access the soundLoader which is initialized at the start of the game.

2
General / Re: Game resolution dilemma
« on: February 02, 2015, 01:55:27 am »
Cheers for the reply AFS,

I have updated my code to update now on resizing and it works fine, however I need to move my UI view when my player moves which doesn't seem to be a problem but not sure if that is 100% correct :). When you say "I still think that having the view as a member would be better, but whatever :P" what do you mean by a member? could you please explain.

3
General / Re: Game resolution dilemma
« on: February 01, 2015, 05:33:08 pm »
Hello there AFS

I have just updated my code like so

void UserInterface::Draw()
{
        sf::View windowView = _renderService.Window.getView();
        sf::View tempView(sf::FloatRect(windowView.getViewport().left, windowView.getViewport().height, windowView.getSize().x, windowView.getSize().y));
        tempView = _renderService.getLetterboxView(tempView, tempView.getSize().x, tempView.getSize().y);
        _renderService.Window.setView(tempView);
        _renderService.Window.draw(BottomBar);

        for (int i = 0; i < PowerUpIcons.size(); i++)
        {
                _renderService.Window.draw(PowerUpIcons.at(i));
        }

        if (SelectedPower != 0)
        {
                _renderService.Window.draw(PowerSelected);
        }

        _renderService.Window.setView(windowView);
}

But the same thing happens as in my last screenshot, the UI bar will stretch across the whole bottom, can't seem to set the bottom bar to use the same view as the letter box :(

4
General / Re: Game resolution dilemma
« on: January 30, 2015, 10:32:32 am »
That sounds like a perfect idea AFS, I admit my sfml knowledge is a little lacking for the time I have spend using it :( but hey, we are all here to help each other and I am thankful of you guys helping me out :), I will let you know later if I have any more issues.

5
General / Re: Game resolution dilemma
« on: January 30, 2015, 12:45:10 am »
Right,

Gobbles I looked at that piece of code and it seems to be working perfectly, however I am still having an issue, basically me resizing the window does the letterbox effect which is what I want so that is great, however I have myself a user interface which sits at the bottom and moves with the player.

Basically I have a function where I pass in a sf::RenderWindow and then I use that to take the view, update the view and draw my user interface, here is my code

void UserInterface::Draw(sf::RenderWindow& window)
{
        sf::View windowView = window.getView();
        sf::View tempView(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
        window.setView(tempView);
        window.draw(BottomBar);
        window.setView(windowView);
}

I have attached a screenshot with my error result, basically I want the red box to be where the blue box is. Once I have that everything will be fine :D Any chance I could get some more help,

P.S.

I have updated my code like so

sf::View windowView = window.getView();
        sf::View tempView(sf::FloatRect(windowView.getViewport().left, windowView.getViewport().height, windowView.getSize().x, windowView.getSize().y));
        window.setView(tempView);
        window.draw(BottomBar);

        for (int i = 0; i < PowerUpIcons.size(); i++)
        {
                window.draw(PowerUpIcons.at(i));
        }

        if (SelectedPower != 0)
        {
                window.draw(PowerSelected);
        }

        window.setView(windowView);

The second attachment is the new result, but as you can see the bar fills the whole width, not just the correct ratio as the game does.

6
General / Re: Game resolution dilemma
« on: January 29, 2015, 09:01:57 pm »
Cheers for the reply Hapax,

Any chance you could send me a link to the post you saw, I just searched the wiki for aspect and I can't find anything :(

7
General / Re: Game resolution dilemma
« on: January 29, 2015, 12:47:07 am »
Yo eXpl0it3r I have taken a look at the sfml view and I kinda understand it, I already use a view to draw my user interface, but basically when I resize my window this is what happens to my game.

I just want everything to stretch out to fill the render window

8
General / Re: Game resolution dilemma
« on: January 28, 2015, 03:35:49 pm »
well at the moment i'm just using a renderwindow with no view, I am only using a view when I want to display the user interface, I take it I should apply a view on the renderwindow straight up and keep using that view instead of applying a view when I want to draw a sprite in an absolute screen position?

9
General / Re: Game resolution dilemma
« on: January 28, 2015, 03:04:37 pm »
personally I would like everything to stretch out but keep a correct ratio for example 4:3 so 800 by 600

10
General / Game resolution dilemma
« on: January 28, 2015, 12:56:45 pm »
Hello there,

I'm having a bit of a hard time with this one, basically I have myself a game which at the moment is perfect for 1024 by 768, now when I made the game full screen some of my graphics start to float because I am using a view, other graphics just stretch out. However this is a huge issue for me.

First off is it ok to code a game to work with just one resolution I.E. the game is coded for 800:600 ratio 4:3 so if the user makes the window taller or wider the ratio will keep stuff in place and stretch to fit the ratio,

Second is there a better way or is that the best way?

I'm want to try and create a game this year and release it to the public (fingers crosses), however the whole idea of different resolutions is quite scary, can anyone help me out understand how I can get around this or how to deal with such a problem.

Cheers for reading

11
General / Re: Scrolling background loop however produces little gaps
« on: January 27, 2015, 11:49:17 pm »
Just tried

   
if (postion.x <= -576)
    {
        levelBackgroundSprites[i].setPosition(1152, postion.y);
    }
    else if (postion.x > 1152)
    {
        levelBackgroundSprites[i].setPosition(-576, postion.y);
    }

didn't seem to work :(

Update

In more testing and some small code changes it is working fine, however your comment did help me Hapax so cheers for that mate

12
General / Scrolling background loop however produces little gaps
« on: January 27, 2015, 11:38:12 pm »
I have myself a parallaxing background, i'm using SFML to render my background, I have myself 3 sf::Sprites, each sprite has the width of 576, I create myself 3 sprites with x positions 0, 576 and 1152. I then have some if statements that will move the background sprites when they go so far off the screen however... small gaps keep appearing, here is my code for my background manager

void BackgroundManager::Update(int playerXVel)
{
//Update level backgrounds
for (int i = 0; i < 3; i++)
{
    sf::Vector2f postion = levelBackgroundSprites[i].getPosition();
    levelBackgroundSprites[i].setPosition(postion.x += playerXVel, postion.y);

    if (postion.x <= -576)
    {
        levelBackgroundSprites[i].setPosition(1152, postion.y);
    }
    else if (postion.x >= 1152)
    {
        levelBackgroundSprites[i].setPosition(-576, postion.y);
    }
}
}
 

I have attached a screenshot

13
General / Re: Memory Violation odd error with sf::Sprite
« on: January 11, 2015, 11:18:20 pm »
Thank you Jesper Juhl for that however my std::vector seems to be working fine for me, also my vector holds the textures and when I setup a new sprite i provide it a pointer to a texture that is stored int eh std::vector. eXpl0it3r what you said is true but it wasn't the cause, but yea just moving the variables seemed to work :)

14
General / Re: Memory Violation odd error with sf::Sprite
« on: January 11, 2015, 08:23:39 pm »
Just to let you guys know, I changed my header file like so

#pragma once

#include "SFML\Graphics.hpp"
#include "ImageLoader.h"
#include <vector>

class UserInterface
{
private:
        ImageLoader& _imageLoader;
        bool setup;
public:
        int SelectedPower;
        int Powers[9];
        std::vector<sf::Sprite> PowerUpIcons;
        sf::Sprite BottomBar;
        sf::Sprite PowerSelected;

        UserInterface(ImageLoader& imageLoader);
        ~UserInterface();

        void Setup();
        void SetupPowerUps();
        void Draw(sf::RenderWindow& window);
        void Update();
        void AddPower();
};

I moved my sf::Sprite BottomBat sprite below the std::vector and now I don't get an error. This is sweet because it is fixed but still why would I get this error?

15
General / Memory Violation odd error with sf::Sprite
« on: January 11, 2015, 08:03:15 pm »
Hello there,

I have myself a ImageLoader which stores a vector of sf::Textures. now here is the odd problem I am having, I have myself a class known as UserInterface.

Here is the header file
#pragma once

#include "SFML\Graphics.hpp"
#include "ImageLoader.h"
#include <vector>

class UserInterface
{
private:
        ImageLoader& _imageLoader;
public:
        int SelectedPower;
        int Powers[9];
        sf::Sprite Bar;
        std::vector<sf::Sprite> PowerUpIcons;
        sf::Sprite PowerSelected;

        UserInterface(ImageLoader& imageLoader);
        ~UserInterface();

        void Setup();
        void SetupPowerUps();
        void Draw(sf::RenderWindow& window);
        void Update();
        void AddPower();
};

Here is the cpp file
#include "UserInterface.h"

UserInterface::UserInterface(ImageLoader& imageLoader) :
_imageLoader(imageLoader)
{
        SelectedPower = 0;
        Powers[1] = 0;
        Powers[2] = 0;
        Powers[3] = 0;
        Powers[4] = 0;
        Powers[5] = 0;
        Powers[6] = 0;
        Powers[7] = 0;
        Powers[8] = 0;
        Powers[9] = 0;
}

UserInterface::~UserInterface()
{

}

void UserInterface::Setup()
{
        Bar.setTexture(_imageLoader.Images[ImageNames::UI_BottomBar]);
        Bar.setPosition(0, 675);

        PowerSelected.setTexture(_imageLoader.Images[ImageNames::UI_Power_Selected]);
        PowerSelected.setPosition(-100, -100);

        SetupPowerUps();
}

void UserInterface::SetupPowerUps()
{
        for (int i = 0; i < 9; i++)
        {
                sf::Sprite newSprite;
                switch (i)
                {
                case 0: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up1]); break;
                case 1: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up2]); break;
                case 2: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up3]); break;
                case 3: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up4]); break;
                case 4: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up5]); break;
                case 5: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up6]); break;
                case 6: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up7]); break;
                case 7: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up8]); break;
                case 8: newSprite.setTexture(_imageLoader.Images[ImageNames::UI_Power_Up9]); break;
                }
               
                newSprite.setPosition(328 + (i * 41), 700);
                newSprite.setTextureRect(sf::IntRect(0, 0, 38, 38));
                PowerUpIcons.push_back(newSprite);
        }
}

void UserInterface::Update()
{
        PowerSelected.setPosition(328 + ( (SelectedPower - 1) * 41), 700);
}

void UserInterface::Draw(sf::RenderWindow& window)
{
        sf::View tempView(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
        window.setView(tempView);

        //Bar.setTexture(_imageLoader.Images[ImageNames::UI_Power_Selected]);
        //Bar.setPosition(0, 640);

        window.draw(Bar);

        for (int i = 0; i < PowerUpIcons.size(); i++)
        {
                window.draw(PowerUpIcons.at(i));
        }

        window.draw(PowerSelected);
}

void UserInterface::AddPower()
{
        SelectedPower++;
}

Now basically if you look at my Setup function it sets up the Bar sf::Sprite and sets up the PowerSelected sf::Sprite, it sets the texture and also sets the position, now in my Draw function, it sets up a view and then draws out the bar, my powers and powerselected sprite. however when it attempts to draw Bar it comes up with this error

Unhandled exception at 0x0F1BE57E (sfml-graphics-d-2.dll) in ColourGalaxy.exe: 0xC0000005: Access violation reading location 0x00000004.
this error is thrown in function
void RenderTarget::draw(const Drawable& drawable, const RenderStates& states)
{
    drawable.draw(*this, states);
}
Look at the image attached to see my error.

Now here is the bit that confuses me. If I comment out my window.draw(Bar); everything works fine. so if though I am setting up my PowerSelected sf::Sprite in the same function as the Bar variable. PowerSelected has no problem at all being drawn. Can anyone help me understand why my Bar variable is causing the memory violation?

Pages: [1] 2 3 ... 8
anything