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

Pages: 1 2 [3] 4
31
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 11:00:35 am »
Good sir, I am using SFML 1.6 :]

32
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 10:18:32 am »
Quote

You should let it run and break at the exact position of the crash. Then look at the call stack and local variables.


I don't have a ton of experience debugging and I would love to learn, so I'm choosing this point to work off of. I did that, and it showed me that the function responsible for the problem is sf::RenderTarget::Clear. I do not know what this function is unfortunately, but I can surmise it's one that occurs behind the lines, so to speak. And it's during that function call, the screen() function.

A few other pieces of information I have access to that don't mean anything to me because I don't know what they stand for but which I'm assuming are heavily important are as follows:

0x0026b788  <+0040>  call     *0x14(%eax)

I'm going to assume this is assembly language. These bits of information are where the debugger is telling me the problem is occurring, with the EXC_BAD_ACCESS alert. I find this very interesting, and I wish I knew what it meant.

Thanks again for your help. I'm hoping we're getting closer to solving this problem. :][/quote]

33
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 09:30:35 am »
Well, if you take out the sound parts, it will work. I tried several piece-out, piece-out, piece-in approaches, but I still can't figure it out, which is why I must consult the powers above (you, Laurent ;]) to help me tackle this problem... and I found something interesting.

I plugged in the handy dandy Xcode debugger and set several breakpoints.... like I anticipated, it revolves around this bit:

Code: [Select]

// Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }


and that makes reference to the function posted in my last reply. What I found out is I'm getting what programmers supposedly dread: EXC_BAD_ACCESS. And that's all it tells anyone in C++ (there are ways to make it a little more evident with Objective-C). But it's on the line with the screen() function call, which may mean the problem exists either within the call or the definition.

From my research, it means that what I'm doing there is trying to access memory that has been released already. But I don't see where that might have happened... For all I know, it could be something related to how the library itself is programmed, because I know you incorporated automatic memory management into SFML.

I hope this shed a little more light on the situation. Thank you much for your help :]

34
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 08:40:50 am »
The issue is that I just don't know where the problem might be... so I find it hard to simplify the code. Before I tried to add in sound, the program worked wonderfully, and it was hardly more complex than the example shown above. But once I put those objects and functions in there with Sound and SoundBuffer, it just won't run. It's showing white, so it's not getting past this part:

Code: [Select]

// Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      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();
     }
   
     // Opening screen
     if (gameStart)
     {
        screen(App, titleSprite, View);
       gameStart = false;
     }


...which means that it has to call this function:

Code: [Select]

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


However, that function hasn't changed since before I put in the sound features, and before, it worked perfectly. So would that mean that maybe there's an issue with the initialization of any objects to the point where the program would crash upon its execution? To me, it's a difficult problem to pinpoint, and unfortunately I can't think of a way to truncate the code that would isolate the problem :/ I hope that helped in any sort of way to clarify things though.... I greatly appreciate your help :]

Colton[/code]

35
Audio / SFML and 8/16-Bit Music?
« on: December 15, 2010, 07:57:34 am »
8-bit music and 16-bit music were just references to the 8-bit and 16-bit platforms that used those types of music. I don't really know what technology the music itself was referred to beneath... probably had more to do with a sampling rate than that. But from what I know and what I've learned, the sound effects were pretty much just digital, primitive sound waves with some effects or contortions applied to them (sine, sawtooth, square, etc.). I'm not familiar with the SoundBuffer class from the SFML library to know whether it can do that or not... I'm sure Laurent or someone of much more expertise than me could say so :] But I read something about creating a custom SoundBuffer object just with an array of samples. I don't know if this would achieve the desired effect, and I haven't the slightest clue how to go about trying to use that feature.

But I have found an easy alternative to use in the meantime, and it's a program called sfxr that generates 8-bit sound effects for you with various parameters that you can manipulate and randomize and then export in a .wav format. I believe they make a port for both Mac and Windows, and I use the Mac port. If anyone wants a clearer idea of what I'm referring to, including Laurent if you wish to consider implementing something like this within the next release of SFML (but in a programmable sense), then here's the link that will take you to the site, and it's a free application:

http://www.drpetter.se/project_sfxr.html

I don't know whether simply using the .wav-exported versions of these sound effects or actually programmed sound effects would be faster at runtime. I don't know enough about that to make a judgment. Perhaps y'all might know? :]

36
Audio / Evasive Bug... Could Be Anything
« on: December 15, 2010, 07:50:32 am »
Hello :] I went back to an old Pong game I had written several months ago the other day and finished it up.... well, almost. It was working fairly well, with the title screen, losing screen, winning screen, etc. functioning normally. However, it had no sound effects, so I added a sound effect for when the paddles hit the ball. It took me some trial and error in figuring out how to compile the program once I created a buffer and a Sound object (and I had forgotten to link the audio framework, but I took care of that to seal the compilation deal ;]). However, it's compiled now.... the only problem is, it just shows me the very familiar white screen of infinite loop death. I am compiling this under Xcode 3.1.4 on my MacBook, but I don't think that has anything to do with it. Rather, I think something had to have gotten messed up when I added in the sounds. Here, I'll post the source code... it's a bit lengthy, but I commented a bit. Note: I have learned how to code better than this and I know I should have built classes for it, but this was before I learned anything about OOP. I just wanted to clean this project up and finish it so I could be done with it forever :p Here goes:

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>

// Function prototypes
int distance(int, int, int, int);
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&);
void calculateBall(int&, int&, sf::Clock&, int&, int&, int&, double&, sf::Sound&);
void drawScore(sf::RenderWindow&, int&, int, int);
void screen(sf::RenderWindow&, sf::Sprite&, sf::View&);

// ENUMS
   enum BallDirection // Different directions/velocities
   {
      UpRight, DownRight, UpLeft, DownLeft
   };
   
   enum PaddleDirection // Different directions/velocities
   {
      Up, Down, Still
   };

// ************ //

// Paddle structure declaration
struct Paddle
{
   int x, y; // Paddle coordinates, upper left
   int botx, boty; // Paddle coordinates, bottom right
   int direction; // Paddle going up or down?
   sf::Clock PaddleTimer; // Movement timer
   
   Paddle(int xcoord, int ycoord, int bottomx, int bottomy, PaddleDirection direc) // Constructor
   {
      x = xcoord;
 y = ycoord;
 botx = bottomx;
 boty = bottomy;
 direction = direc;
   }
};

// Ball structure declaration
struct Ball
{
   int x, y; // Ball's position in the field
   int size; // Ball's size
   int direction; // Ball's current direction/velocity
   double speed; // Speed (less is more)
   sf::Clock BallTimer; // Movement timer
   
   Ball(int xcoord, int ycoord, int ballSize, double ballSpeed = 0.7)
   {
      x = xcoord;
 y = ycoord;
 size = ballSize;
   }
};

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// View declaration -- Atari resolution
sf::View View(sf::FloatRect(0, 0, 192, 160));

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

// Images for screens
sf::Image titleImage;
sf::Image winningImage;
sf::Image losingImage;

// Sprites for screens
sf::Sprite titleSprite;
sf::Sprite winningSprite;
sf::Sprite losingSprite;

// Audio variables
sf::SoundBuffer paddleBuffer;
sf::Sound paddleSound;

   // Player and ball declarations
   // **PLAYER 1**
   Paddle Player1(5, 60, 7, 70, Still);
   
   // **PLAYER 2**
   Paddle Player2(184, 60, 186, 70, Still);
   
   // **BALL**
   Ball Ball(80, 80, 2);

int main()
{
   // Game start variable
   bool gameStart = true;

   // Score variable
   
   int score1 = 0, score2 = 0;
   
   // Ball's speed
   double ballSpeed = 0.03;
   
   // Load buffer
   paddleBuffer.LoadFromFile("paddle_hit.wav");
   
   // Set sound
   paddleSound.SetBuffer(paddleBuffer);
   
   // Load images
   titleImage.LoadFromFile("pong_title.png");
   winningImage.LoadFromFile("you_win.png");
   losingImage.LoadFromFile("you_lose.png");
   
   // Set smoothness off
   titleImage.SetSmooth(false);
   winningImage.SetSmooth(false);
   losingImage.SetSmooth(false);

   // Initialize sprites
   titleSprite.SetImage(titleImage);
   winningSprite.SetImage(winningImage);
   losingSprite.SetImage(losingImage);
   titleSprite.SetPosition(0,0);
   winningSprite.SetPosition(0,0);
   losingSprite.SetPosition(0,0);
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      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();
 }
 
 // Opening screen
 if (gameStart)
 {
    screen(App, titleSprite, View);
gameStart = false;
 }
 
 // Game loop activities
 
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer);
 
 // Calculate ball
 calculateBall(Ball.x, Ball.y, Ball.BallTimer, Ball.direction, score1, score2, ballSpeed, paddleSound);
 
 // Clear previous screen
 App.Clear();
 
 // Draw the paddles and the ball
 App.Draw(sf::Shape::Rectangle(Player1.x, Player1.y, Player1.botx, Player1.boty, sf::Color::White));
 App.Draw(sf::Shape::Rectangle(Player2.x, Player2.y, Player2.botx, Player2.boty, sf::Color::White));
 App.Draw(sf::Shape::Circle(Ball.x, Ball.y, Ball.size, sf::Color::Blue));
 
 // Draw scores
 drawScore(App, score1, 30, 5);
 drawScore(App, score2, 160, 5);
 
 // Set the View
 App.SetView(View);
 
 // Lose or Win?
 if (score1 == 10)
 {
    screen(App, winningSprite, View);
score1 = 0;
score2 = 0;
 }
 
 if (score2 == 10)
 {
    screen(App, losingSprite, View);
score1 = 0;
score2 = 0;
 }
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
} // end main

// Functions and their declarations

// Distance formula
int distance(int x1, int y1, int x2, int y2)
{
   int temp = pow((x2 - x1), 2) + pow((y2 - y1), 2);
   return sqrt(temp);
}

// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2)
{
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::Down)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 < 150)
 {
         y1++;
    boty1++;
 }
 Pad1.Reset();
   }
   
   if ((Input.IsKeyDown(sf::Key::Q)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 > 0)
 {
         y2--;
    boty2--;
 }
 Pad2.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::A)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 < 150)
 {
         y2++;
    boty2++;
 }
 Pad2.Reset();
   }
}

// Calculate ball and its movement
void calculateBall(int &x, int &y, sf::Clock& ballTime, int &direc, int &score1, int &score2, double &ballSpeed, sf::Sound &paddle)
{
   if (ballTime.GetElapsedTime() >= ballSpeed)
   {
      if (direc == UpRight) // Ball traveling up and to the right?
 {
    if (x >= 192)
{
   score1++;
x = y = 80;
ballTime.Reset();
direc = UpLeft;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = UpLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y--;
x++;
   ballTime.Reset();
}

return;
 }
 
 if (direc == DownRight) // Ball traveling down and to the right?
 {
    if (x >= 192)
{
       score1++;
   x = y = 80;
   ballTime.Reset();
   direc = UpLeft;
ballSpeed = 0.03;
}
    else if (y >= 158)
{
   direc = UpRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = DownLeft;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x++;
ballTime.Reset();
}

return;
 }
 
 if (direc == UpLeft) // Ball traveling up and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y <= 3)
{
   direc = DownLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = UpRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   x--;
y--;
ballTime.Reset();
}

return;
 }
 
 if (direc == DownLeft) // Ball traveling down and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
ballSpeed = 0.03;
}
else if (y >= 158)
{
   direc = UpLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = DownRight;
ballTime.Reset();
ballSpeed -= 0.002;
paddle.Play();
}
else
{
   y++;
x--;
ballTime.Reset();
}

return;
 }
 
 else
    return;
   }
}

// Draw the number of the score for either player
void drawScore(sf::RenderWindow &myApp, int &score, int x, int y)
{
   switch (score)
   {
      case 0:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 1:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 2:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 3:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 4:
    myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 5:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
break;
 case 6:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y + 4, x + 5, y + 8, 1, sf::Color::White));
break;
 case 7:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
 case 8:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 8, x + 5, y + 8, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
break;
 case 9:
    myApp.Draw(sf::Shape::Line(x, y, x + 5, y, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y, x, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x, y + 4, x + 5, y + 4, 1, sf::Color::White));
myApp.Draw(sf::Shape::Line(x + 5, y, x + 5, y + 8, 1, sf::Color::White));
break;
}
}

// Function to display a static screen that waits for the user to press return (or enter)
void screen(sf::RenderWindow &myApp, sf::Sprite &screenshot, sf::View &myView)
{
   bool proceed = false;
   sf::Event myEvent;
   
   const sf::Input& myInput = App.GetInput();
   
   while (!proceed)
   {
      myApp.Clear();
      myApp.Draw(screenshot);
      myApp.SetView(myView);
      myApp.Display();
 myApp.GetEvent(myEvent);
 myApp.GetInput();
     
 if (myInput.IsKeyDown(sf::Key::Return))
 {
    proceed = true;
 }
   }
}


Perhaps one of you awesome people can figure out what I must have done wrong..... I've tried to avoid infinite loops as best I can (which usually causes this problem for me), but I may have missed something. All the images and the .wav file are in the right directory (where the program target is). All of the frameworks are linked properly, as well. As always, any help is greatly appreciated and will further my quest to game program and lead me to post more interesting game example questions than Pong in this forum to spice it up ;] Haha, thanks everybody.

Colton

37
Audio / SFML and 8/16-Bit Music?
« on: September 21, 2010, 09:59:01 pm »
Hello, everybody :]

Now that I've gotten SFML's audio abilities to work, I'm somewhat at a loss as to how I can get started making and using my own 8-bit and 16-bit music for games I will make in the future. Is it possible to use that style of music in SFML? I'm assuming I would need midi or some other format. I can imagine how to get it working with .wav and other types of standard audio formats, but those aren't going for the space-saving and programmability that I would like to be using. Essentially, I suppose you could say I'd like to have a programmable sort of music in my games, perhaps using just plain source code, which I've read is how it used to be done, since there was only so much space on game media formats in the past.

Any links, advice, tips, or help of any kind would be greatly appreciated. :] Thank you in advance.

Colton

38
Audio / Audio Doesn't Seem to be Linking?
« on: September 21, 2010, 09:40:48 pm »
Nevermind, I found the answer! :p I wasn't linking to the libraries in Xcode that deal with audio.... foolish, foolish, foolish :/ But thanks to y'all anyway :]

39
Audio / Audio Doesn't Seem to be Linking?
« on: September 21, 2010, 09:21:15 am »
Hello, everybody.

I'm trying to incorporate the use of the SFML audio package in a little testing application I've put together. Here's the code for the actual program:

Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Audio.hpp>

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(640, 480), "SFML Graphics");

sf::SoundBuffer spitBuffer;
spitBuffer.LoadFromFile("Memo.wav");

sf::Sound spit(spitBuffer);
float pitchCount = 1;

    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear screen
        App.Clear();
pitchCount += .01;

spit.SetPitch(pitchCount);

spit.Play();

        // Draw apredefined shape
        App.Draw(sf::Shape::Circle(200, 200, 100, sf::Color::Yellow, 10, sf::Color::Blue));

        // Finally, display the rendered frame on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


And here's what I get from my IDE (Xcode):

Line Location Tool:0: collect2: ld returned 1 exit status
Line Location Tool:0: symbol(s) not found
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::SetPitch(float)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::SoundBuffer()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::Sound(sf::SoundBuffer const&, bool, float, float, sf::Vector3<float> const&)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::Play()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::~SoundBuffer()", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::SoundBuffer::LoadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
Line Location Tool:0: _main in main.o
Line Location Tool:0: "sf::Sound::~Sound()", referenced from:

No idea exactly what this means, but I'm assuming it has to do with a linking problem. However, there are no errors with the rest of the code that has to do with the SFML library; in fact, without the Audio package functions and whatnot, the program will run fine and render the circle included in the program. I made sure the .wav file used in the program is also in the right place and everything. I would greatly appreciate some help on how to fix this problem :] I am running Mac OS 10.5.

Thanks in advance!

Colton[/code]

40
Window / Set Background Color Mac OS X
« on: September 08, 2010, 11:00:08 pm »
Ohhh I see :/ I plan on eventually learning Objective-C, but it wasn't on my short-term agenda... shoot. :p Well thanks for your help.... I suppose I can see what is required and it probably wouldn't be terribly difficult to implement a window or view with Cocoa, but I'm trying to focus on SFML and C++ :p

Laurent, if you're viewing, I think the next build should have SetBackgroundColor again O:] But I understand there are a lot of other issues to work with besides that.

Thanks for your help, Hiura. Guess I've hit a stumbling block :p I appreciate the help and time though :]

41
Window / Set Background Color Mac OS X
« on: September 08, 2010, 09:24:30 pm »
Thank you very much for your reply, Hiura :]

I'm thinking I'll have to tackle the first option, considering I don't think I have a good enough level of skill to mess with the library :p I'm just going to compile and run the program on Mac OS X for now... just to get it all working. Once I've done that and I want to cross-compile or port it, I'll consider doing the windowing for the other two. But can you please explain to me exactly what I need to do for that first option? I looked at the function for that class as you said, but I don't know what I must do to solve the problem with it. I apologize, as I don't have much experience with this library.... I've only made a couple little things with it :p

Thank you very much for your time.

Colton

42
Window / Set Background Color Mac OS X
« on: September 08, 2010, 05:49:14 pm »
I see, I see... Thank you much. Is there any possible way for me to use an alternate function or process to make a transparent window? For the game I'm conceiving of, that's essentially what really makes it worthwhile to make for me. I appreciate the help :]

43
Window / Set Background Color Mac OS X
« on: September 08, 2010, 05:31:01 pm »
Hello, everybody. I'm trying to make the background color of my render window transparent, so I tried to use the sf::RenderWindow::SetBackgroundColor function; however, it doesn't appear that the function exists with my documentation and build of SFML (1.6), even though it's on the online reference. Is this function exclusive to a build of SFML after 1.6, or is there something I'm missing? I would appreciate some help :] Thanks in advance.

Colton

44
SFML projects / My First Game
« on: May 09, 2010, 12:26:44 pm »
Hey, everybody. :] Since I'm new at making games and also new with using SFML, I thought I'd share my first (well, second...) game that I've made using it. (The first game could hardly be called a game. It was just a little "game" where you shoot a devil sprite that follows you around. That project was more of an experiment with different techniques that just evolved into a crappy little program eventually. :p

But I made Pong, at least a watered-down version of it. Here's the source, if anyone wants to compile it and have a mess-around with it:

Code: [Select]

/* This game is basically a simple remake of Pong. It will be for two players. */

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

// Function prototypes
int distance(int, int, int, int);
void getInput(int&, int&, int&, int&, sf::Clock&, sf::Clock&);
void calculateBall(int&, int&, sf::Clock&, int&, int&, int&);

// ENUMS
   enum BallDirection // Different directions/velocities
   {
      UpRight, DownRight, UpLeft, DownLeft
   };
   
   enum PaddleDirection // Different directions/velocities
   {
      Up, Down, Still
   };

// ************ //

// Paddle structure declaration
struct Paddle
{
   int x, y; // Paddle coordinates, upper left
   int botx, boty; // Paddle coordinates, bottom right
   int direction; // Paddle going up or down?
   sf::Clock PaddleTimer; // Movement timer
   
   Paddle(int xcoord, int ycoord, int bottomx, int bottomy, PaddleDirection direc) // Constructor
   {
      x = xcoord;
 y = ycoord;
 botx = bottomx;
 boty = bottomy;
 direction = direc;
   }
};

// Ball structure declaration
struct Ball
{
   int x, y; // Ball's position in the field
   int size; // Ball's size
   int direction; // Ball's current direction/velocity
   double speed; // Speed (less is more)
   sf::Clock BallTimer; // Movement timer
   
   Ball(int xcoord, int ycoord, int ballSize, double ballSpeed = 0.7)
   {
      x = xcoord;
 y = ycoord;
 size = ballSize;
   }
};

// Render window declaration
sf::RenderWindow App(sf::VideoMode(800, 600), "T4 Pong");

// View declaration -- Atari resolution
sf::View View(sf::FloatRect(0, 0, 192, 160));

// Event Receiver
sf::Event Event;

// Input Receiver
const sf::Input& Input = App.GetInput();

   // Player and ball declarations
   // **PLAYER 1**
   Paddle Player1(5, 60, 7, 70, Still);
   
   // **PLAYER 2**
   Paddle Player2(184, 60, 186, 70, Still);
   
   // **BALL**
   Ball Ball(80, 80, 2);

int main()
{
   // Score variable
   
   int score1 = 0, score2 = 0;
   
   // Start initialization / escape sequences (events)
   while (App.IsOpened())
   {
      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();
 }
 
 // Game loop activities
 
 // Process input
 getInput(Player1.y, Player1.boty, Player2.y, Player2.boty, Player1.PaddleTimer, Player2.PaddleTimer);
 
 // Calculate ball
 calculateBall(Ball.x, Ball.y, Ball.BallTimer, Ball.direction, score1, score2);
 
 // Clear previous screen
 App.Clear();
 
 // Draw the paddles and the ball
 App.Draw(sf::Shape::Rectangle(Player1.x, Player1.y, Player1.botx, Player1.boty, sf::Color::White));
 App.Draw(sf::Shape::Rectangle(Player2.x, Player2.y, Player2.botx, Player2.boty, sf::Color::White));
 App.Draw(sf::Shape::Circle(Ball.x, Ball.y, Ball.size, sf::Color::Blue));
 
 // Set the View
 App.SetView(View);
 
 // Display final image
 App.Display();
 
   } // End loop
   
   return EXIT_SUCCESS;
} // end main

// Functions and their declarations

// Distance formula
int distance(int x1, int y1, int x2, int y2)
{
   int temp = pow((x2 - x1), 2) + pow((y2 - y1), 2);
   return sqrt(temp);
}

// Process inputs and move players accordingly
void getInput(int &y1, int &boty1, int &y2, int &boty2, sf::Clock &Pad1, sf::Clock &Pad2)
{
   App.GetInput();
   
   if ((Input.IsKeyDown(sf::Key::Up)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 > 0)
      {
    y1--;
    boty1--;
 }
 Pad1.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::Down)) && (Pad1.GetElapsedTime() >= 0.01))
   {
      if (y1 < 150)
 {
         y1++;
    boty1++;
 }
 Pad1.Reset();
   }
   
   if ((Input.IsKeyDown(sf::Key::Q)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 > 0)
 {
         y2--;
    boty2--;
 }
 Pad2.Reset();
   }
   else if ((Input.IsKeyDown(sf::Key::A)) && (Pad2.GetElapsedTime() >= 0.01))
   {
      if (y2 < 150)
 {
         y2++;
    boty2++;
 }
 Pad2.Reset();
   }
}

// Calculate ball and its movement
void calculateBall(int &x, int &y, sf::Clock& ballTime, int &direc, int &score1, int &score2)
{
   if (ballTime.GetElapsedTime() >= 0.03)
   {
      if (direc == UpRight) // Ball traveling up and to the right?
 {
    if (x >= 192)
{
   score1++;
x = y = 80;
ballTime.Reset();
direc = UpLeft;
}
else if (y <= 3)
{
   direc = DownRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = UpLeft;
ballTime.Reset();
}
else
{
   y--;
x++;
   ballTime.Reset();
}

return;
 }
 
 if (direc == DownRight) // Ball traveling down and to the right?
 {
    if (x >= 192)
{
       score1++;
   x = y = 80;
   ballTime.Reset();
   direc = UpLeft;
}
    else if (y >= 158)
{
   direc = UpRight;
ballTime.Reset();
}
else if ((x >= 184 && x <= 186) && (y >= Player2.y && y <= Player2.boty))
{
   direc = DownLeft;
ballTime.Reset();
}
else
{
   y++;
x++;
ballTime.Reset();
}

return;
 }
 
 if (direc == UpLeft) // Ball traveling up and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
}
else if (y <= 3)
{
   direc = DownLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = UpRight;
ballTime.Reset();
}
else
{
   x--;
y--;
ballTime.Reset();
}

return;
 }
 
 if (direc == DownLeft) // Ball traveling down and to the left?
 {
    if (x <= 0)
{
   score2++;
x = y = 80;
ballTime.Reset();
direc = UpRight;
}
else if (y >= 158)
{
   direc = UpLeft;
ballTime.Reset();
}
else if ((x >= 5 && x <= 7) && (y >= Player1.y && y <= Player1.boty))
{
   direc = DownRight;
ballTime.Reset();
}
else
{
   y++;
x--;
ballTime.Reset();
}

return;
 }
 
 else
    return;
   }
}


Any critiques of my code would be appreciated. I'm just now getting into classes and objects so I was more comfortable using structures to bundle all the data together. I'm fairly new at C++, so I expect I have much to learn. One of the things I really want to learn is how to make my code as efficient and memory-conserving as possible.

Appreciate the read, guys, and thanks for making such a great library, Laurent! :]

Colton

45
Graphics / Graphics/Window Scaling
« on: May 03, 2010, 08:45:31 pm »
I got a good enough method working as of now with an sf::View. When drawing primitives, they still look virtually the same and not old, but that's okay for now. I'm sure with drawing sprites, it takes into account their scaling and makes them look as old as they need to look.

I appreciate the help, guys. :]

Pages: 1 2 [3] 4
anything