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 - 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 / Re: Drawing inside the Game loop / RectangleShape?
« on: April 17, 2019, 09:23:05 pm »
You store a reference or index in a vector or similar for all the sprites that should be rendered. Then you just iterate that vector and render those sprites.

You shouldn't have multiple clear(), draw(), display() loops, but just one.

How can I do that?

4
Graphics / Re: Drawing inside the Game loop / RectangleShape?
« on: April 17, 2019, 08:44:10 pm »
The code is incomplete, so it's quite hard to tell.

Are you sure you don't set another position to your sprite inside the game loop?

Also, you should not call window.draw / window.display only if a given event happened.

Keep the rendering outside of the event handling method, see examples in tutorial https://www.sfml-dev.org/tutorials/2.5/graphics-draw.php

actually since i am using  an if else condition in the main loop i will also have to draw the sprite there only and the problem with that is that the sprite is only visible for 1 frame so is there a way around this?

5
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();
                                               

                                               
                                        }

6
System / Re: Detecting a mouse click inside a "Not Defined" Rectangle.
« on: April 16, 2019, 07:25:09 pm »
If you have 9 rectangular areas to detect then make 9 rectangular areas?
You can create an sf::FloatRect for area 1, another for area 2, another for area 3, etc. and check in which rect the mouse is.

I read the actual documentation but I still dont understand how it is used. Can you explain me please?

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

8
Is this C++? Because that's not how you check if a number is between 2 others in C++.  ???
random google result

SFML rectangles have a contains function to check if a point (the mouse position) is inside a rectangle.

yeah that can really help me out but another problem i will face is that the 9 boxes you see arent 9 rectangles. they are 2 big rectangles. one placed horizontally and one placed vertically in the respective places and an additional on in the Centre coz one rectangle overlapped the other. get it? so what function can i use?
also i used the link you provided and tried that just now. doesnt cout "work" even once.

9
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.

10
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?

11
Graphics / Re: Failed to load image.
« on: April 15, 2019, 07:19:30 pm »
Don't link to sfml-xxx.lib (release libraries) when you build in Debug mode. It should be sfml-xxx-d.lib (debug libraries).



this worked. firstly i checked the libraries, I found that i had installed sfml-graphics along with sfml-graphics-d

then i changed my config from build to release and voila it worked. thanx a lot man. appreciate it.

12
Graphics / Re: Failed to load image.
« on: April 15, 2019, 02:29:00 pm »
Don't link to sfml-xxx.lib (release libraries) when you build in Debug mode. It should be sfml-xxx-d.lib (debug libraries).




Actuall i am the biggest noob in this universe and dont know the difference. all i know i did is I followed how to install on wikihow. Here is the link

https://www.wikihow.com/Set-Up-SFML-in-a-Project-on-Visual-Studio-2017

13
Graphics / Re: Failed to load image.
« on: April 15, 2019, 02:13:52 pm »
Most likely you're linking the debug SFML in release mode, or the release SFML in debug mode.

What do you mean? how do i solve this? Also i have attached a picture so as to explain what i get.

14
Graphics / Re: Failed to load image.
« on: April 15, 2019, 02:12:32 pm »
Also, use \\ or / in string literals. The single back-slash is used for escape sequences.

didnt work i did try it. still shows the things i have linked in the attachment. also the white thing that you see on the right side is the windows which is supposed to be black.


15
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]