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

Pages: [1]
1
Graphics / Maths and Rotations
« on: August 26, 2011, 06:29:52 am »
That is only a small problem, SFML is really great.

2
Graphics / Maths and Rotations
« on: August 20, 2011, 07:23:38 am »
Hello. I'm using SFML 1.6 and I am having problems trying to rotate a sprite because the axis of rotation is located in the upper left corner. How could I rotate the sprite with an axis of rotation located at the center of the sprite without changing permanently the center of the sprite? All the logic of my code is based on the sprite's center located in the upper left corner and I wondered if there was any alternative to perform this rotation without using SetCenter () at the beginning of the code, perhaps with some maths and sprite->Move (). I tried the following:

sprite->SetCenter(sprite-> GetSize (). x / 2.0f, sprite-> GetSize ().y / 2.0f);
sprite->Rotate (angle);
sprite->SetCenter (0, 0);

It does not work because the sprite moves when I move the center, resulting in the sprite rotates around its upper left corner.

3
Audio / Exception using sf::music
« on: March 10, 2011, 07:44:25 pm »
Yes, I only delete the pointer when the destructor of the game class is called.
I tried this at the manageKeyboardInput class:
Code: [Select]
case FINALSTAGE:
{
if(Event->Key.Code == sf::Key::N)
app->Close();

if(Event->Key.Code == sf::Key::S)
{
Initialize();
backgroundMusic = new sf::Music();
       backgroundMusic->OpenFromFile("Ambient.ogg");
backgroundMusic->SetLoop(true);
       backgroundMusic->Play();
}

break;
}


This worked perfect. I looked around the code and I could not find any statement where I lose the pointer (using delete or otherwise).
What it could be? I still don't know.

4
Audio / Exception using sf::music
« on: March 10, 2011, 07:05:57 pm »
Hi, I did that.
The error  message of the exception is:

"Unhandled exception at 0x00f4cd86 in TP4Final.exe: 0xC0000005: Access violation reading location 0x736c7584."

Last instructions on the stack are:

"tp4final.exe!sf::SoundStream::Play() + 0c36 bytes"
"tp4final.exe!Game::ManageKeyboardInput() Line 218"

The last line (sf::soundstream......) has a yellow arrow at the left side and the game trows the exception there. When I do double click in that line, the next warning shows up:

"There is no source code available for the current location".

I don't know what it could be.

5
Audio / Exception using sf::music
« on: March 10, 2011, 06:30:12 pm »
You're right :D. Well, I'll write some pieces of code.
The function that handles the keyboard input to change the stage is:

 
Code: [Select]
while(app->GetEvent(*Event))
{
if(Event->Type == sf::Event::KeyPressed)
{
if(Event->Key.Code == sf::Key::Escape)
app->Close();

switch(stage)
{
case INITIALSTAGE:
{
if(Event->Key.Code == sf::Key::Space)
{
Initialize();
backgroundMusic->Play();
}

break;
}

case GAMESTAGE:
{
if(Event->Key.Code == sf::Key::Space)
Initialize();

break;
}

case FINALSTAGE:
{
if(Event->Key.Code == sf::Key::N)
app->Close();

if(Event->Key.Code == sf::Key::S)
{
Initialize();
                                                / / here I had written: backgroundMusic-> Play () / / at this point throws the exception
}

break;
}
}
}
}

Then at the end of my function "Update" I check the status of the game (If I win or lose).

Code: [Select]

if(lifes == 0)
{
state = LOSE;
stage = FINALSTAGE;
backgroundMusic->Stop();
}

else if(points == 1000)
{
state = WIN;
stage = FINALSTAGE;
backgroundMusic->Stop();
}


Game loop is:
Code: [Select]

Initialize();

clock->Reset();

while(app->IsOpened())
{
ManageKeyboardInput();

CollisionDetection();

Update();

Draw();
}


This is only part of the finished code. If you need it I can send you the finished code

6
Audio / Exception using sf::music
« on: March 10, 2011, 05:32:15 pm »
Hi. Well my problem is this: I have a small game, which is divided into three "stages. " The first is the initial screen (it only shows a static image) and has no music, then pressing a key change to the next stage. The second stage is the game screen. Here I start to play background music (by pressing a key in the initial stage, I call Play of the object "sf:: Music "). Then, win or lose the game, I move to a third stage (the final stage). In the final stage, I draw the last frame I drew in the game screen, and also a message (sf:: string) that says if you won or not. Here what I do is stop playing the music (when I'm checking if he wins or loses in the game screen I pause playback). Also what I do is give to the player the possibility to restart the game(returning to the game screen). When I do this I want to play music again and visual studio 2008 throws an exception.
What could be the problem? I'm using pointers to a single object "sf:: music".
I could not find a similar problem in the forum.
I tried to play and pause the music within the game screen by using two different keys and it works perfect. The problem is when I want to change the final stage to the game screen again.

7
Graphics / About switching between images
« on: February 27, 2011, 10:56:34 pm »
What if I have two images loaded in different sf::image objects and you want to display one image or another depending of the situation?
I mean, I have a class named character and I need a method to change the image to display. I was trying something like this:

( in main() )

Code: [Select]
sf::image *img1 = new sf::image();
sf::image *img2 = new sf::image();
img1->loadfromfile("img1.png");
img2->loadfromfile("img2.png");
sprite->setimage(*img1);
Character *character = new Character(*img1);
/* in the class I do  image = img1, where "image" is sf::image *image; */


and later in the game I need to change the sf::image of the character, then I do something like
Code: [Select]
character->setimage(*img2);
/* in the class i tried this:
delete image;
image = img2;
sprite->setimage(*image);*/


and trows and exception.
What is wrong? How can I do that in the right way?
Thanks.

8
Window / Thanks
« on: December 29, 2010, 05:12:54 pm »
Hi! What I wanted to do is to stop my character when I just press (not while I'm pressing) 'a' and 'd' keys simultaneously (assuming that the character is still moving). I finally use Input. Something like this:

Code: [Select]
if(input.isKeyDown(sf::keys::a) && input.isKeyDown(sf::keys::d))
{
      //stop character
}

But I can't achieve same behavior using Events. I try to take two events consecutively:

Code: [Select]
while(app.getEvent(Event))
{
     if(Event.type == sf::event::keyPressed)
     {
            if(Event.key.code == sf::key::a)
            {
                   app.getEvent(Event); //to read the next event

                   if(Event.type == sf::event::keyPressed)
                   {
                          if(Event.key.code == sf::key::d)
                          {
                                  //stop character
                           }
                   }

            }
      }
}


But I doesn't work. What am I doing wrong?

Thank you very much for your help!

9
Window / About key combinations
« on: December 29, 2010, 03:48:08 am »
Hi, I'm using the object Event to handle keyboard events and I need to do some things when I press simultaneously 'a' and 'd'. How can I do such thing?
Another question, if I use the object input to handle keyboard events ¿Is there some way to know when a key is released?
Thanks!

10
Window / About moving a sprite with a gamepad
« on: October 29, 2010, 11:16:37 pm »
Thanks Epaik, that helps me a lot. But I don't understand why you put < -0.5 as a second parameter of getjoyaxis()

11
Window / About moving a sprite with a gamepad
« on: October 21, 2010, 04:31:32 pm »
Hi everyone. I have a little problem. I was reading the tutorials and I want to move a sprite on the screen using the gamepad, but I don't understand how to use joystick input (buffered or unbuffered), I mean, how to take and do something with I trigger some event. Can you give me some orientation about using class input and event?. Thanks!

Pages: [1]