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 - Captain Lightning

Pages: [1]
1
Graphics / Sprite.GetSubRect().Intersects() constantly returns true
« on: September 22, 2011, 02:27:32 am »
After trying to use sf::Sprite.GetSubrect().Intersects() I've come to find that no matter what, it always returns true. This can be tested with the following code:

Code: [Select]
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include "games.h"

struct Square
{
    sf::Sprite Sprite;
    sf::Image Image;
    sf::String String;
    Square();
};

Square::Square()
{
    Image.Create(100, 100, sf::Color(255,255,255));
    Sprite.SetImage(Image);
    String.SetFont(sf::Font::GetDefaultFont());
}

int Collision_Test(sf::RenderWindow &App)
{
    Square S1, S2, S3;
    S1.Image.Create(100, 100, sf::Color(255,0,0)); // Red Square
    S2.Image.Create(100, 100, sf::Color(0,255,0)); // Green Square
    S3.Image.Create(100, 100, sf::Color(0,0,255)); // Blue Square
    S1.Sprite.SetPosition(250, 250); // Left Bottom
    S2.Sprite.SetPosition(375, 250); // Right Bottom
    S3.Sprite.SetPosition(300, 300); // Center Top
    S1.String.SetPosition(App.GetWidth()/2, App.GetHeight()/8);
    S2.String.SetPosition(App.GetWidth()/2, App.GetHeight()/6);
    bool Switched = false;
    while (App.IsOpened())
    {
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
            {
                App.Close();
            }

            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            {
                App.Close();
            }
        }

        const sf::Input& Input = App.GetInput();
        bool Space_Down = Input.IsKeyDown(sf::Key::Space);
        if (Space_Down)
        {
            if (Switched)
            {
                S1.Sprite.SetPosition(250, 250); // Left Bottom
                S2.Sprite.SetPosition(375, 250); // Right Bottom
                S3.Sprite.SetPosition(300, 300); // Center Top
                Switched = false;
            }
            else
            {
                S1.Sprite.SetPosition(100, 250); // Left Bottom
                S2.Sprite.SetPosition(500, 250); // Right Bottom
                S3.Sprite.SetPosition(300, 500); // Center Top
                Switched = true;
            }
        }

        // Collision Logic
        if (S1.Sprite.GetSubRect().Intersects(S2.Sprite.GetSubRect()))
        {
            S1.String.SetText("Red is currently touching Green.");
        }
        else
        {
            S1.String.SetText("Red is not touching Green.");
        }
        if (S2.Sprite.GetSubRect().Intersects(S1.Sprite.GetSubRect()))
        {
            S2.String.SetText("Blue is currently touching Red.");
        }
        else
        {
            S2.String.SetText("Blue is not touching Red.");
        }



        App.Clear();
        App.Draw(S1.Sprite);
        App.Draw(S2.Sprite);
        App.Draw(S3.Sprite);
        App.Draw(S1.String);
        App.Draw(S2.String);
        App.Display();
    }
}

2
Audio / sf::soundbuffer plays no sound
« on: September 14, 2011, 10:34:18 pm »
sf::music works just fine for me, but for some reason playing a sound using sf::soundbuffer creates no response.

My code:
Code: [Select]

    // Init sounds
    sf::SoundBuffer hit_sb, step_sb;
    if (!hit_sb.LoadFromFile("audio/hit.wav") && step_sb.LoadFromFile("audio/step.wav"))
    {
        return EXIT_FAILURE;
    }
    sf::Sound step(step_sb);
    std::cout << "Duration: " << step_sb.GetDuration() << " Status: " << step.GetStatus();


It returns:
Code: [Select]
Duration: 0 Status: 0

Pages: [1]