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

Pages: [1]
1
Graphics / Disable click through overlapping shapes?
« on: April 20, 2019, 05:42:31 pm »
I am really close to building my project but I am encountering one simple problem. I have a rectangle on which I have use the GetGlobalBounds to check if mouse clicks on it. Now I am drawing over another Rectangle over that rectangle and using GetGlobalBounds on the overlapping Rectangle. Now when i click on the overlapping one, the command for the original Rectangle is executed instead of the one that is overlapping. How can I prevent this?

2
Graphics / How can I check if a Sprite has a texture loaded or not?
« on: April 18, 2019, 08:23:06 pm »
I want to apply an if condition that if sprite does not have texture, then run.

3
Graphics / Drawing inside the Game loop / RectangleShape?
« on: April 17, 2019, 10:49:16 am »
I am using a switch to check the position of the mouse click and then display the sprite at the clicked location.
I am using this. But  the sprite comes for one frame and then goes away. also i have placed the switch inside the main game loop. So is there a way I can fix the Sprite once it is spawned so that it doesnt despawn. Or is there a way so that i can place my sprite automatically Inside the rectangle and also check if cell_1 == cell_2 == cell_3 so the player wins
case Event::MouseButtonPressed:

                                if (event.mouseButton.button == Mouse::Left) {

                                        if (Cell_1.getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window)))) {
                                       
                                                cout << "Cell 1" << endl;
                                                window.draw(sprite);
                                                sprite.setPosition(Vector2f(125.f, cell_height));
                                                window.display();
                                               

                                               
                                        }

4
System / Detecting a mouse click inside a "Not Defined" Rectangle.
« on: April 16, 2019, 07:08:15 pm »
It sounds weird but i have created a big box with three rectangles. The three rectangles are shown in picture.
their starting points are :
1.Halfway of the box vertically.                                        Size :  750,200  (Purple colored)
2.Halfway of the box horizontally                                     Size :  200,600  (Red colored)
3.In the middle where the 2 rectangles collide                  Size :  250,200  (Orange colored)

now i have made a grid for TIC TAC TOE  without defining all the 9 cells one by one. Now I have detect when the user clicks on cell 1 (look at the picture) and so on. How can I detect that?

5
By box or rectangle I do not refer to the rect drawn by me. I want to know if a user clicked in a place. I am making a tic tac toe program and I want to register the click. i have been using this


                Vector2i winpos = Mouse::getPosition(window);
                int loc_x = winpos.x;
                int loc_y = winpos.y;

                INPUT:
                if (Mouse::isButtonPressed(Mouse::Left)) {
                       

                        if (72 < loc_x < 250 && 600 < loc_y < 500) {

                                cout << "works" << endl;
                               
                        }

                }
               
 
also i have placed this code inside the while loop
it should cout "works" in the cmd when i click in the first block but gives me "works" everytime i click inside
the window. it should not do that. it should only gimme works if mouse clicks in 1st cell/block.
look picture for clarification.

6
I have a custom font and i have set a huge size ( 160) and the underline i get is real thin. so is there a way?

7
Graphics / Failed to load image.
« on: April 15, 2019, 01:28:23 pm »
so i am very new to SFML (less then 24 hrs) and i have encountered with a weird problem. I am trying to load a texture and when i run my code, the cmd shows "failed to load ... " in the very beginning and then prints all sort of weird random gibberish stuff. I am using visual studio 2017 and SFML 2.5 . Also i found my working dir by using system(dir) and placed my png there but still doesnt work. also if i remove the "if condition" everything is fine. Here is my code :
#include <SFML/Graphics.hpp>
#include "iostream";
 using namespace std;
 using namespace sf;
 int main()
 {
    RenderWindow window(VideoMode(1000, 1000), "Chiggy's Tic Tac Toe!");
    CircleShape shape(100.f);
    shape.setFillColor(Color::Blue);
    Texture texture;
    if (!texture.loadFromFile("D:\Developement\VisualStudio\sfml\try\Project0\Project0\mad.png")) {  
         
           cout<<"Mario failed to load horribly"<<endl; system("pause"); //return EXIT_FAILURE; }

     while (window.isOpen()) {

           Event event;
           
            while (window.pollEvent(event)) {
                 if (event.type == Event::Closed)
                 window.close();
}

 window.clear(Color::Black);
 window.draw(shape);
 window.display();
}
return 0; }

Pages: [1]