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

Pages: [1]
1
left and top are not functions  >:(
don't be mad bbz :c

2
Okay sweet. I finally made working buttons. woot woot! :)
Thanks everyone!

3
Try assignments.

I just tried that, and I think it's working. Could you explain why you have to assign some, and other's is like in parenthesis?
like for example
sf::RectangleShape myRectangleShape;
myRectangleShape.setFillColor(sf::Color::Blue); <---- parenthesis

sf::FloatRect myFloatRect;
myFloatRect.top = 20; <----- assignment

4
term does not evaluate to a function taking 1 arguments
Which term? Which function is being called?

IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type   
Which expression? Where in the code does this happen?

Code: [Select]
//Inside of the Button Class's constructor function
                buttonSize = size;
rectShape.setSize(buttonSize);
rectShape.setFillColor(color);
rectShape.setPosition(position);
rectBoundingBox.left(20); //<----------------------------
rectBoundingBox.top(20);  //<------------------------------------

5
Error   1   error C2064: term does not evaluate to a function taking 1 arguments
   3   IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type   

Code: [Select]
class Button{
public:
Button(sf::Vector2f size,sf::Vector2f position, sf::Color color)
{
buttonSize = size;
rectShape.setSize(buttonSize);
rectShape.setFillColor(color);
rectShape.setPosition(position);
rectBoundingBox.left(20);
rectBoundingBox.top(20);


}

6
Okay, So I've made considerable changes to le code. I made a class called Button to, well you know, make buttons. Here is the code currently.

Code: [Select]
#include <iostream>
#include <string>
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>


using namespace std;

class Button{
public:
Button(sf::Vector2f size,sf::Vector2f position, sf::Color color)
{
buttonSize = size;
rectShape.setSize(buttonSize);
rectShape.setFillColor(color);
rectShape.setPosition(position);
}
sf::Vector2f getButtonSize()
{
return buttonSize;
}
sf::RectangleShape getRectShape()
{
return rectShape;
}
private:
sf::Vector2f buttonSize;
sf::RectangleShape rectShape;
sf::FloatRect rectBoundingBox;

};

int main()

{
sf::Vector2f defaultButtonSize(120,50);

Button button1(defaultButtonSize,sf::Vector2f(35,200), sf::Color::Red);
Button button2(defaultButtonSize,sf::Vector2f(35,280), sf::Color::Blue);
Button button3(defaultButtonSize,sf::Vector2f(35,360), sf::Color::Cyan);

sf::ContextSettings settings;
settings.antialiasingLevel = 8;

sf::RenderWindow window(sf::VideoMode(800,600), "My window.");
sf::Music music;
if(!music.openFromFile("sound.wav"))
std::cout << "failed to open sound.wav" << std::endl;
music.play();

sf::Font font;
if(!font.loadFromFile("sansation.ttf"))
std::cout << "failed to open sansation.tff" << std::endl;

sf::Text text("Welcome to click the boxes!", font, 50);
sf::Text text2("Would you like easy, medium,\n or hard mode?\n\n\n\t\tEasy\n\n\n\t\tMedium\n\n\n\t\tHard", font, 25);
text2.move(0,100);

while (window.isOpen())
{
sf::Vector2i Mousepos;

sf::Event event;
while(window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left)
{

}
}
}
window.clear();

window.draw(button1.getRectShape());
window.draw(button2.getRectShape());
window.draw(button3.getRectShape());
window.draw(text);
window.draw(text2);

window.display();
}
}

My current problem is in my Button class. I need to give rectBoundingBox it's size and position (which needs to be identical to the sf::RectangleShape rectShape)

I see that I can do rectBoundingBox.left, top, width and height. But I'm not sure what left coordinate and top coordinate means... and I also get an error. :P

7
You'll want to use code tags:
[code=cpp]

Also, where do you set Mousepos? My guess is you're forgetting to get the mouse position relative to the window. Like this:
boundingBox.contains(sf::Vector2f(sf::Mouse::getPosition(window)))
 

It also wouldn't be a bad idea to wrap the functionality of a button into a class, so your code is simpler to read and it's easier to make more than one button.
Yup. I did have a line that got my mouse's position and stored it into a vector2f, but I accidently deleted it :(.
I might try making this into a class, that will give me something good to work on, as I'm still not that great with classes, and they're important in c++ lol :P

8
       
Code: [Select]
sf::Vector2f rect1coord(35,200);
sf::Vector2f rect1size(120,50);
sf::Vector2f rect1coord2(155, 250);

sf::Vector2f rect2coord(35,280);
sf::Vector2f rect2size(120,50);

sf::Vector2f rect3coord(35,360);
sf::Vector2f rect3size(120,50);

sf::FloatRect rect1(rect1coord, rect1coord2);
sf::FloatRect rect2(rect2coord,(rect2coord + rect2size));
sf::FloatRect rect3(rect3coord,(rect3coord + rect3size));

Okay, so above I made a bunch of vector2fs and plugging it into Float Rects, as you can see above, and Also using for RectangleShape below. (I have 3 of them for 3 different buttons.)
Code: [Select]
        sf::RectangleShape rectangle1(rect1size);
rectangle1.setFillColor(sf::Color(0,0,0));
rectangle1.setOutlineThickness(10.0f);
rectangle1.setOutlineColor(sf::Color(255,105,180));
rectangle1.move(rect1coord);
Here's the output that I want for clicking one of the buttons.
Code: [Select]
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left)
{
if(rect1.contains(Mousepos.x,Mousepos.y))
{
cout << "You Picked Easy Mode\n\n" << endl;
}
if(rect2.contains(Mousepos.x,Mousepos.y))
{
cout << "You Picked Medium Mode\n\n" << endl;
}
if(rect3.contains(Mousepos.x,Mousepos.y))
{
cout << "You Picked Hard Mode\n\n" << endl;
}
Basically, If I put (0,0,100,100) into rect1, (using no vector2f) It obviously makes a clickable 100 by 100 pixel area. I can click it and it will cout "You picked easy mode".

but If I put like anything higher than 0 in the first xand y coordinate, or if I use the vector2f's its not working. I can't figure it out :/


[Sorry I don't know what the heck happened, it said I already posted when I didnt.)

9
Graphics / Having trouble making clickable menu buttons. Failing hard.
« on: March 01, 2014, 02:08:40 am »
[see next post]

Pages: [1]