[SFML] Dialog box
Ostatnio zmodyfikowano 2024-05-29 19:36
tBane Temat założony przez niniejszego użytkownika |
» 2024-05-28 18:10:24 pokazałbyś mi przykład jak w takim razie poprawnie zaprogramować tę funkcję renderującą DialogBox ? void renderDialogBox( sf::RenderWindow * window, int currentPage = 0 ) { page = currentPage; sf::Texture * dialogBoxTexture = new sf::Texture(); dialogBoxTexture->loadFromFile( "assets/GUI/DialogBoxTexture.png" ); background = new sf::Sprite(); background->setTexture( * dialogBoxTexture ); background->setOrigin( dialogSize.x / 2.0f, dialogSize.y / 2.0f ); background->setPosition( view.getCenter().x, view.getCenter().y + screenHeight / 2.0f - dialogSize.y / 2.0f ); std::vector < sf::Text * > texts; texts.clear(); sf::Text * text; sf::Vector2f textPosition; for( int i = 0; i < 4; i++ ) { if( i + 4 * page < wrappedText.size() ) text = new sf::Text( wrappedText[ i + 4 * page ], * basicFont, characterSize ); else text = new sf::Text( "", * basicFont, characterSize ); text->setFillColor( sf::Color::White ); textPosition.x = background->getPosition().x - dialogSize.x / 2.f + padding; textPosition.y = background->getPosition().y - dialogSize.y / 2.f + float( i ) * lineHeight + padding; text->setPosition( textPosition ); texts.push_back( text ); } window->draw( * background ); for( auto & text: texts ) window->draw( * text ); }
|
|
pekfos |
» 2024-05-28 18:22:33 void renderDialogBox( sf::RenderWindow * window, int currentPage = 0 ) { page = currentPage; sf::Texture dialogBoxTexture; dialogBoxTexture.loadFromFile( "assets/GUI/DialogBoxTexture.png" ); sf::Sprite background; background.setTexture( dialogBoxTexture ); background.setOrigin( dialogSize.x / 2.0f, dialogSize.y / 2.0f ); background.setPosition( view.getCenter().x, view.getCenter().y + screenHeight / 2.0f - dialogSize.y / 2.0f ); window->draw( background ); for( int i = 0; i < 4; i++ ) { if( i + 4 * page >= wrappedText.size() ) break; sf::Text text( wrappedText[ i + 4 * page ], * basicFont, characterSize ); text.setFillColor( sf::Color::White ); sf::Vector2f textPosition; textPosition.x = background.getPosition().x - dialogSize.x / 2.f + padding; textPosition.y = background.getPosition().y - dialogSize.y / 2.f + float( i ) * lineHeight + padding; text.setPosition( textPosition ); window->draw( text ); } } |
|
DejaVu |
» 2024-05-28 18:22:39 Nadal nie rozumiem czemu nie używasz ChatGPT 4o do takich pytań: #include <SFML/Graphics.hpp> #include <vector>
void renderDialogBox( sf::RenderWindow * window, int currentPage = 0 ) { int page = currentPage; sf::Texture dialogBoxTexture; if( !dialogBoxTexture.loadFromFile( "assets/GUI/DialogBoxTexture.png" ) ) { return; } sf::Sprite background; background.setTexture( dialogBoxTexture ); background.setOrigin( dialogSize.x / 2.0f, dialogSize.y / 2.0f ); background.setPosition( view.getCenter().x, view.getCenter().y + screenHeight / 2.0f - dialogSize.y / 2.0f ); window->draw( background ); sf::Vector2f textPosition; for( int i = 0; i < 4; i++ ) { sf::Text text; if( i + 4 * page < wrappedText.size() ) { text.setFont( * basicFont ); text.setString( wrappedText[ i + 4 * page ] ); text.setCharacterSize( characterSize ); } else { text.setFont( * basicFont ); text.setString( "" ); text.setCharacterSize( characterSize ); } text.setFillColor( sf::Color::White ); textPosition.x = background.getPosition().x - dialogSize.x / 2.f + padding; textPosition.y = background.getPosition().y - dialogSize.y / 2.f + float( i ) * lineHeight + padding; text.setPosition( textPosition ); window->draw( text ); } }
|
|
tBane Temat założony przez niniejszego użytkownika |
» 2024-05-28 18:57:06 Dobra, pozbędę się wskaźników dla obiektów sfml:: i zobaczę czy nadal będą wycieki pamięci.
// przerobiłem cały kod i nie ma już wycieków, więc jest git :-) |
|
tBane Temat założony przez niniejszego użytkownika |
» 2024-05-29 19:36:04 bool talkWithCharacter() { float x1, y1, rx1, ry1; float x2, y2, rx2, ry2; x1 = player->position.x; y1 = player->position.y; rx1 =( player->radius + player->actionRange ); ry1 =( player->radius + player->actionRange ) / 2.0f; for( auto & character: characters ) { x2 = character->position.x; y2 = character->position.y; rx2 =( character->radius + character->actionRange ); ry2 =( character->radius + character->actionRange ) / 2.0f; if( intersectionsTwoEllipses( x1, y1, rx1, ry1, x2, y2, rx2, ry2 ) ) { gameState = gameStates::dialog; setTextToDialogBox( character->dialog ); page = 0; return true; } } return false; }
|
|
1 « 2 » |