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

Pages: [1]
1
Actually, not the solution to my problem. If you see the code that is using only main, that works. I thank that you showed me how to use that constructor. I will have more time tonight to actually mess around with the library, and just going to go str8 to other code I will get to the debugger too...

2
I'm not totally sure on how to use the debugger. My output does tell me where the problem lies... unfortunately I don't know what really to do with it.

Quote
(gdb) run
Starting program: /home/ken/Documents/SFMLGOD/test/menu/a.out
[Thread debugging using libthread_db enabled]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff78af693 in sf::Input::IsMouseButtonDown(sf::Mouse::Button) const ()
   from /usr/local/lib/libsfml-window.so.1.6
(gdb) continue
Continuing.

Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.


As you can see it's coming from the window library? On top of that, it's coming from my IsMouseButtonDown() function. I thought I used this properly. I'm a bit new to classes and their members and how to really manipulate/use them.

^obvious haha

3
It seg faults. Could this be my machine?

Is it possible that it's because I'm not limiting my frames and sometimes achieves idk 1k fps?

If so, how do I manipulate max frame rate?

4
EDIT: the problem is segmentation faults... When I go over the box that is the sprites.
The sprites are simply 100x30 boxes that sit on each other. While I go over the box it draws the second box that's a different color, and I have another one that when I click it, it turns a different color.

Hi, I have a RenderWindow variable that's being pretty annoying, or it could, of course, be my fault. This variable is initialized in main(), but it's acting up when I try to use its functions outside of main.

I would like someone to look over it and see what's wrong. I'll print the two versions that I have -- outside of main and inside of main.

inside of main
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#define ONE "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/bluetest.png"
#define TWO "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/greentest.png"
#define THREE "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/purpletest.png"
#define POSX 300
#define POSY 200




int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test for the button etc");


sf::Image One;
sf::Image Two;
sf::Image Three;
std::vector<sf::Sprite> bSprite(3);


if(!One.LoadFromFile(ONE))
{
std::cout << ONE << std::endl;
return EXIT_FAILURE;
}
if(!Two.LoadFromFile(TWO))
{
std::cout << TWO << std::endl;
return EXIT_FAILURE;
}
if(!Three.LoadFromFile(THREE))
{
std::cout << THREE << std::endl;
return EXIT_FAILURE;
}


bSprite[0].SetImage(One);
bSprite[1].SetImage(Two);
bSprite[2].SetImage(Three);


bSprite[0].SetPosition(POSX, POSY);
bSprite[1].SetPosition(POSX, POSY);
bSprite[2].SetPosition(POSX, POSY);


while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();




App.Clear();


sf::Mouse::Button b;

if(App.GetInput().GetMouseX() >
bSprite[1].GetPosition().x &&
App.GetInput().GetMouseX() <
bSprite[1].GetPosition().x + 100 &&
App.GetInput().GetMouseY() >
bSprite[1].GetPosition().y  &&
App.GetInput().GetMouseY() <
bSprite[1].GetPosition().y + 30 &&
App.GetInput().IsMouseButtonDown(b) == true ) //end
App.Draw(bSprite[2]);


else if(App.GetInput().GetMouseX() > bSprite[1].GetPosition().x && App.GetInput().GetMouseX() < bSprite[1].GetPosition().x + 100 && App.GetInput().GetMouseY() > bSprite[1].GetPosition().y  && App.GetInput().GetMouseY() < bSprite[1].GetPosition().y + 30 )
App.Draw(bSprite[1]);


else
App.Draw(bSprite[0]);
App.Display();

}

return EXIT_SUCCESS;
}


outside of main
Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>
#include <iostream>
#define ONE "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/bluetest.png"
#define TWO "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/greentest.png"
#define THREE "/home/ken/Documents/SFMLGOD/test/menu/clip4menu/purpletest.png"
#define POSX 300
#define POSY 200




void add(sf::Image*, int, std::vector<sf::Sprite> &);
int check(sf::RenderWindow*, std::vector<sf::Sprite> &);


int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test for the button etc");


sf::Image One;
sf::Image Two;
sf::Image Three;
std::vector<sf::Sprite> bSprite(3);


if(!One.LoadFromFile(ONE))
{
std::cout << ONE << std::endl;
return EXIT_FAILURE;
}
if(!Two.LoadFromFile(TWO))
{
std::cout << TWO << std::endl;
return EXIT_FAILURE;
}
if(!Three.LoadFromFile(THREE))
{
std::cout << THREE << std::endl;
return EXIT_FAILURE;
}



add(&One, 0, bSprite);
add(&Two, 1, bSprite);
add(&Three, 2, bSprite);


bSprite[0].SetPosition(POSX, POSY);
bSprite[1].SetPosition(POSX, POSY);
bSprite[2].SetPosition(POSX, POSY);



while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();



int x;

App.Clear();
x = check(&App, bSprite);
if( x != 1)
{
App.Draw(bSprite[0]);
App.Display();
}
}

return EXIT_SUCCESS;
}



void add(sf::Image *b, int i, std::vector<sf::Sprite> & bSprite)
{


bSprite[i].SetImage(*b);

}

int check(sf::RenderWindow * g, std::vector<sf::Sprite> & bSprite)
{

sf::Mouse::Button b;

if(g->GetInput().GetMouseX() >
bSprite[1].GetPosition().x &&
g->GetInput().GetMouseX() <
bSprite[1].GetPosition().x + 100 &&
g->GetInput().GetMouseY() >
bSprite[1].GetPosition().y  &&
g->GetInput().GetMouseY() <
bSprite[1].GetPosition().y + 30 &&
g->GetInput().IsMouseButtonDown(b) == true )
{
g->Draw(bSprite[2]);
return 1;
}

if(g->GetInput().GetMouseX() > bSprite[1].GetPosition().x && g->GetInput().GetMouseX() < bSprite[1].GetPosition().x + 100 && g->GetInput().GetMouseY() > bSprite[1].GetPosition().y  && g->GetInput().GetMouseY() < bSprite[1].GetPosition().y + 30 )
{
g->Draw(bSprite[1]);
return 1;
}

return 0;
}

Thanks in advance :)

5
Graphics / problem with loading images from file
« on: June 03, 2011, 03:56:45 am »
haha, i didn't write out the function calls in check right.... a lot of functions are missing their () parentheses.... but now it's segmentation faults

6
Graphics / problem with loading images from file
« on: June 03, 2011, 02:55:20 am »
I've figured out my problem :(

7
Graphics / problem with loading images from file
« on: June 03, 2011, 12:02:19 am »
I've broken down the program though... When I try to load these files they mess up, and that's where the problem is. When I try to manipulate them through the sprite that the images are assigned though via x.SetImage(), it fails and these errors come up:


Quote
btest1.cpp: In function ‘int check(sf::RenderWindow*)’:
btest1.cpp:76: error: invalid use of member (did you forget the ‘&’ ?)
btest1.cpp:78: error: ‘bSprite.std::vector<_Tp, _Alloc>::operator[] [with _Tp = sf::Sprite, _Alloc = std::allocator<sf::Sprite>](1ul)->sf::Drawable::GetPosition’ does not have class type
btest1.cpp:80: error: invalid use of member (did you forget the ‘&’ ?)
btest1.cpp:82: error: invalid use of member (did you forget the ‘&’ ?)
btest1.cpp:83: error: no matching function for call to ‘sf::Input::IsMouseButtonDown() const’
/usr/local/include/SFML/Window/Input.hpp:72: note: candidates are: bool sf::Input::IsMouseButtonDown(sf::Mouse::Button) const
btest1.cpp:89: error: invalid use of member (did you forget the ‘&’ ?)
btest1.cpp:89: error: ‘bSprite.std::vector<_Tp, _Alloc>::operator[] [with _Tp = sf::Sprite, _Alloc = std::allocator<sf::Sprite>](1ul)->sf::Drawable::GetPosition’ does not have class type
btest1.cpp:89: error: invalid use of member (did you forget the ‘&’ ?)
btest1.cpp:89: error: invalid use of member (did you forget the ‘&’ ?)



EDIT: Also after one of the loadfromfile functions... the semi colon has been removed and there still is a problem in case you caught that or just noticed etc.  So it has nothing to do with loading the images... but something with using the sprites. IDK, i recently (like yesterday) learned about vectors. I'm not sure what is going on.

8
General discussions / When is sfml2 due out?
« on: June 02, 2011, 09:47:57 pm »
When's the big sfml 2 coming out exactly?

I might just start fuqin with it now...

9
Graphics / problem with loading images from file
« on: June 02, 2011, 08:36:19 pm »
They are all valid locations... I copied them from the shell exactly from file paste from nautilus and copy pasted to actual file...


They are all jpegs... is that the reason... possibly it's too much for the Image etc??

10
Graphics / problem with loading images from file
« on: June 02, 2011, 03:26:22 pm »
also here is the code that derived the earlier code

Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>
#define ONE
#define TWO
#define THREE
#define POSX 300
#define POSY 200


std::vector<sf::Sprite> bSprite(3);

void add(sf::Image, int);
int check(sf::RenderWindow*);


int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test for the button etc");

sf::Image One;
sf::Image Two;
sf::Image Three;
if(!One.LoadFromFile(ONE))
return EXIT_FAILURE;
if(!Two.LoadFromFile(TWO))
return EXIT_FAILURE;
if(!Three.LoadFromFile(THREE));
return EXIT_FAILURE;

add(One, 0);
add(Two, 1);
add(Three, 2);


bSprite[0].SetPosition(POSX, POSY);
bSprite[1].SetPosition(POSX, POSY);
bSprite[2].SetPosition(POSX, POSY);



while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();



int x;

App.Clear();
x = check(&App);
if( !x == 1)
App.Draw(bSprite[0]);
App.Display();
}

return EXIT_SUCCESS;
}



void add(sf::Image b, int i)
{
bSprite[i].SetImage(b);


}

int check(sf::RenderWindow * g)
{

while(g->GetInput().GetMouseX >
bSprite[1].GetPosition().x &&
g->GetInput().GetMouseX <
bSprite[1].GetPosition.x + 100 &&
g->GetInput().GetMouseY >
bSprite[1].GetPosition().y  &&
g->GetInput().GetMouseY <
bSprite[1].GetPosition().y + 30 &&
g->GetInput().IsMouseButtonDown() == true )
{
g->Draw(bSprite[2]);
return 1;
}

while(g->GetInput().GetMouseX > bSprite[1].GetPosition().x && g->GetInput().GetMouseX < bSprite[1].GetPosition.x + 100 && g->GetInput().GetMouseY > bSprite[1].GetPosition().y  && g->GetInput().GetMouseY < bSprite[1].GetPosition().y + 30 )
{
g->Draw(bSprite[1]);
return 1;
}

return 0;
}



only problem here is that the check function doesn't work because the sprites...
I'm guessing it's because they fail to load(this doesn't compile at all)

11
Graphics / problem with loading images from file
« on: June 02, 2011, 03:05:03 pm »
hi, when I load these images, it fails for some reason. All are valid locations on the computer.

Code: [Select]

#include <SFML/Graphics.hpp>
#include <vector>
#define ONE
#define TWO  
#define THREE
#define POSX 300
#define POSY 200


std::vector<sf::Sprite> bSprite(3);

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Test for the button etc");

sf::Image One;
sf::Image Two;
sf::Image Three;
if(!One.LoadFromFile(ONE))
return EXIT_FAILURE;
if(!Two.LoadFromFile(TWO))
return EXIT_FAILURE;
if(!Three.LoadFromFile(THREE));
return EXIT_FAILURE;




while(App.IsOpened())
{
sf::Event ev1;
while(App.GetEvent(ev1))
if(ev1.Type == sf::Event::Closed)
App.Close();



int x;

App.Clear();

App.Display();
}

return EXIT_SUCCESS;
}


i took out definitions for one,two, three because of security reasons etc.

12
General / Trying to keep sprite from moving off of the screen.
« on: May 21, 2011, 11:41:32 am »
Thanks for your answers; you guys helped a great deal! :)

13
General / Trying to keep sprite from moving off of the screen.
« on: May 21, 2011, 04:29:56 am »
EDIT: I've figured out why it doesn't work with using a simple cout to print it's coordinates. I'm curious to why it's the opposite of what I thought. As in why when you go up the y coordinate goes down and vice versa. Is there some mathematics or subject that will help me better understand this? I don't want a simple problem like this holding me back anymore :(, as I have bigger fish to fry in the future. Or is this simply how the library is?

I'm making a basic little unrefined game.  :D
I'm having trouble with making sure these sprites don't move off the screen.

My current code is this, but it fails obviously.

Code: [Select]

sf::Vector2f b1Pos = BOARD1.GetPosition();
if (App.GetInput().IsKeyDown(sf::Key::Up) && b1Pos.y < 600.f) BOARD1.Move(0, -200 * ElapsedTime);


this doesn't keep it from moving off the screen while the height of the screen is 600.

Also if this is an easy problem, just tell me why this doesn't work and maybe a few hints to figuring out what will.

Pages: [1]
anything