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

Pages: [1]
1
General / Is SFML message-driven or event-driven?
« on: April 29, 2024, 03:49:48 pm »
i asked ai and it says:

It is based on an event-driven model.In SFML, the main event loop is controlled by the SFML application. The application constantly retrieves events from the event queue and responds accordingly. This event loop is responsible for receiving user input, updating game state, rendering graphics, and other operations.
 
Is it true?

2
Graphics / hello. a question about setTextureRect
« on: March 27, 2024, 05:18:02 pm »
I use RectangleShape to hold the map. I use setTextureRect to adjust the area where the map appears in RectangleShape .
 But if I set the area to exceed the size of the original map, there's a blur of color around it. I wonder if I can remove these colors or make them black
 rectangleShape.setTextureRect(sf::IntRect(-100,-10,9000,9000));
 
The original size was 8000*8000.The picture of the problem is attached

3

when i close my game. the background cmd window show :

Failed to activate OpenGL context:

An internal OpenGL call failed in Texture.cpp<104>
Expression:
 glDeleteTexture(1,&texture)
Error description:
 GL_INVALID_OPERATION
 The specified operation is not allowed in the current stats.

 

4
I fixed an issue that caused a crash at the end of the program using TGUI libraries.
The reason is a flaw in the code design
I built a game state machine, and different game state classes.
Each game state class has a tgui object and draws it
When I created a tgui::button for the GameStatusGaming state, the program ran fine, but when I closed the program, it crashed in vs debug mode

I've tried many versions of tgui with this problem, so it's not a problem with tgui per se
I finally found that these game state classes were not released in my state machine destructor, which is what caused the tgui to crash.
I released them in the destructor of the state machine
        virtual ~GameStatusMachine(){
                //Destruction status class
                for(const auto &status:m_statusList){
                        delete status;
                }
        }
 
But it crashed again after the program ended
I set a breakpoint at the destructor and I see that there's no breakpoint running,This means that the state machine is not destroyed after the program ends
I checked the main function, it created a new game window class, and it didn't get released after the function ended
        GameWindow *window;
        try{
                window = new GameWindow;
        }
        catch(const char *e){
                std::cerr<<e<<"\n";
                return -1;
        }
        window->show();
        return 0;
 

So these status classes and TGUIs are not destroyed after the main function ends, they are still running, waiting for the system to release them.tgui components are still trying to draw,So it leads to a crash
I manually released the game window class,
        delete window;
        return 0;
 
I ran again without crashing at the end

5
General / I found a range-based for loop issue with vs2012
« on: December 19, 2023, 04:16:09 am »
I'm using VertexArray to draw a tilemap
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
        {
                // apply the transform
                states.transform *= getTransform();
                //Range-based for loop is used here, compiling with vs2012 and running with a high cpu usage of 30%,so one cpu core is at full load
                //but threre is no problem with vs2013
                //for (auto content:m_verticesAndTexture){
                //      states.texture = &content.second;
                //      target.draw(content.first, states);
                //}
                //Use the classic for loop instead,The cpu usage returned to normal after compiling with vs2012
                for(int i=0;i<m_verticesAndTexture.size();i++){
                        states.texture = &m_verticesAndTexture[i].second;
                        target.draw(m_verticesAndTexture[i].first, states);
                }

        }
 
I don't think vs2012 supports c++11 very well

6
My SpriteSheet only animates faces to the right, and if I want it to left animation, I have to detect the sprite direction every time the Sprite is updated,and  using transfrom,animation from right to left, but my cpu usage increased by 2%. Is there a better way?
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const{
                states.transform *= getTransform();
                //if sprite orientation left
                if (m_spriteOrientation == SpriteOrientation::LEFT){
                        //set Origin
                        m_sprite->setOrigin(sf::Vector2f(m_sprite->getLocalBounds().width - m_sprite->getOrigin().x, 0));
                        //Horizontal flip,sprite face to left
                        m_sprite->scale(-1.f, 1.f);

                }
                //draw sprite
                target.draw(*m_sprite, states);

                //if sprite orientation left
                if (m_spriteOrientation == SpriteOrientation::LEFT){
                        //Flip back,sprite face to right
                        m_sprite->scale(-1.f, 1.f);
                        //Restore Origin
                        m_sprite->setOrigin(sf::Vector2f(0, 0));
                }

        }
 


7
Graphics / How to set Sprite collision size different from texture size
« on: November 19, 2023, 07:52:37 pm »
when I set the sprite texture size with
sprite.setTextureRect(sf::IntRect(0, 0, 64, 64));
its collision size is set as well, so when I call Sprite.getGlobalBounds () I get that size, but I want the collision size to be less than the texture size, What should be done

8
I would like to translate sfml2.6 official tutorial https://www.sfml-dev.org/tutorials/2.6/ into Chinese and post it on www.csdn.net.    I don't know if it's OK.   Because I did not see sfml official ready-made Chinese version of the tutorial.

9
When using sf::View, the content displayed in the window will change as the perspective moves,How to keep a graphic in a specific position in the window at all times
My current approach is to follow the perspective and change the position of the content, so as to always maintain a specific position in the window. Is there a better way?For example, simply skip the view and draw on the window

Pages: [1]
anything