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

Pages: [1]
1
Graphics / Re: Drawing sf::Text in nested loop
« on: February 15, 2014, 10:09:22 pm »
Sorry :P. My code has been deleted before I sent it. In anger I sent this ugly code.
Tags changed. In polish forum we have [cpp] tags, so I get use write this one.

I hope it will work. I edited that in my smrt phone.

edit: Golden Eagle. I tested that. Debbug says that my font is in sf::Text in each place. Any errors from sfml in console

2
Graphics / Drawing sf::Text in nested loop
« on: February 15, 2014, 08:58:36 pm »
Hi, It's my second attemp to post after this forum unlogged me...
I have interesting problem with rendering sf::Text in menu loop located in main loop. Everthing in menu loop display, expect sf::Text. In main loop everything renders with no problems.

VC++


main.cpp
#include <SFML/Graphics.hpp>
//#include <SFML/System.hpp>
#include <iostream>
#include <Windows.h>
#include <vector>

#include "cButton.h"

sf::RenderWindow window(sf::VideoMode(800, 600), "Mun Lander! Alfa 0.1");
sf::Font font;


void fMenu( bool gameOn, sf::Event & eventG )
{
       
        menu::cButton butKontynuuj(font);
        menu::cButton butNowaGra(sf::String("Nowa Gra"),font);

        //desperation act
         
        sf::ConvexShape sAktDesperacji;
        sAktDesperacji.setPosition(300,300);
        sAktDesperacji.setPointCount(4);
        {
                        sAktDesperacji.setPoint(0, sf::Vector2f(-25,-23));
                        sAktDesperacji.setPoint(1, sf::Vector2f(25,-23));
                        sAktDesperacji.setPoint(2, sf::Vector2f(20,0));
                        sAktDesperacji.setPoint(3, sf::Vector2f(-20,0));
        }

        window.setView(window.getDefaultView());
       
        while (window.isOpen())
        {
               
                while (window.pollEvent(eventG))
        {
                        if (eventG.type == sf::Event::Closed)
                        {
                window.close();
                        }
                        if (eventG.type == sf::Event::KeyPressed && eventG.key.code == sf::Keyboard::Escape )
                        {
                                return;
                        }
                }


               
                window.clear(sf::Color(00,20,20));
               
               
                //desperation act, if it appears... You are in menu

                window.draw(sAktDesperacji);
               
                window.draw(butKontynuuj.drawButton());
                window.draw(butNowaGra.drawButton());
               

                window.display();
        }


}

///////////////////////////////////////////////////////////////////////////////////////////////////////




int main()
{
       
       
   
        window.setFramerateLimit(80);
        sf::View defaultCam(window.getDefaultView());
        sf::View landerCam;

        ///Co&#347;
        sf::FloatRect rectCam(100,100,400,300);
        landerCam.reset(rectCam);
        landerCam.setViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
        /// ekran &#322;adowania

        /// inicjalizacja zmiennych i obiektów gry
       

       
// you should change that
        font.loadFromFile("Volter.ttf");

        sf::Event eventG;

       

        srand( time( NULL ) );
       

        //////////////////////////////////////////////////////////////////////////////
        /// test

        menu::cButton aktDesperacji2(sf::String("*GAME HAPPENS HERE*\nexplosions, craters, and space landers"),font);




               
       
       
        /// g&#322;ówna p&#281;tla gry

    while (window.isOpen())
    {
               

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


                        if (eventG.type == sf::Event::MouseWheelMoved && eventG.mouseWheel.delta > 0 )
                        {
                                landerCam.zoom(1.1f);
                                defaultCam.zoom(1.1f);
                        }
                        if (eventG.type == sf::Event::MouseWheelMoved && eventG.mouseWheel.delta < 0 )
                        {
                                landerCam.zoom(0.9f);
                                defaultCam.zoom(0.9f);
                        }
                        if (eventG.type == sf::Event::KeyPressed && eventG.key.code == sf::Keyboard::Escape )
                        {
////////Here menu starts
                                fMenu( true, eventG );
                                zegFiz.restart();
                        }

                       
        }

               
               
               


        window.clear();
               
                window.setView(window.getDefaultView());

        window.display();
    }

    return 0;
}  
 


cButton.h
#pragma once
#include <SFML/Graphics.hpp>
namespace menu
{

class cButton
{
        sf::String  butString;
        sf::Text butText;



public:
        cButton(sf::Font&);
        cButton(sf::String,sf::Font&);
        ~cButton(void);
        sf::Text const & drawButton();
        sf::Vector2f const getPosition();
       
};

} //namespace
 

cButton.cpp
#include "cButton.h"


namespace menu
{

        cButton::cButton(sf::Font& font)
        {
                butString = "Typical text button";
                butText.setString( butString);
                butText.setPosition(200,200);
                butText.setCharacterSize(30);
                butText.setScale(1,1);
                butText.setFont( font );
        }

        cButton::cButton(sf::String str, sf::Font & font)
        {
                butString = str;
                butText.setString( butString);
                butText.setPosition(200,200);
                butText.setCharacterSize(30);
                butText.setScale(1,1);
                butText.setFont( font );
        }


        cButton::~cButton(void)
        {
        }

        sf::Text const & cButton::drawButton()
        {
                return butText;
        }

        sf::Vector2f const cButton::getPosition()
        {
                return butText.getPosition();
        }

} //namespace menu
 

Regards

btw, English grammar hard very is :)

//edited code, some translations
 

Pages: [1]
anything