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

Pages: 1 ... 31 32 [33] 34
481
General / Problem with compiling AniSprite
« on: January 08, 2012, 06:36:43 pm »
You are probably missing a lib file.

482
General / slow things down a bit
« on: January 08, 2012, 04:34:27 pm »
I tested the following code with SFML2 and it should work.
I think that if u are using SFML 1.6 that you should change the 1000 into a 1.

Code: [Select]
while(Window.IsOpened())
{
    if( up )
    {
        if (Clock.GetElapsedTime() >= 1000)
        {
            ++Time;
            Clock.Reset();
        }
    }
    else
    {
        if (Clock.GetElapsedTime() >= 1000)
        {
            --Time;
            Clock.Reset();
        }
    }

    if( Time >= 170 )
        up = false;

    if( Time <= 0 )
        up = true;
           
}

483
General / slow things down a bit
« on: January 08, 2012, 03:59:55 pm »
You only reset the clock when up is false, also do this when it is true.


There are two ways I see to fix the problem:

1) Does it has to be 170?  If not then you can slow it down by letting it count to e.g. 17000.

2) Change it to something like this:
Code: [Select]
if (up)
{
    if (Clock.GetElapsedTime() > 25)
    {
        ++Time;
        Clock.Reset();
    }
}

By changing the 25 you can adjust the speed.

484
General / slow things down a bit
« on: January 08, 2012, 03:40:55 pm »
Do something like this to also make the clock count backwards (this is an example code, not exactly what you have to write):
Code: [Select]

sf::Clock Clock;
int Time = 0;

while (...)
{
    if (up)
    {
        Time += Clock.GetElapsedTime();
        Clock.Reset();
    }
    else
    {
        Time -= Clock.GetElapsedTime()
        Clock.Reset();
    }
}

485
General discussions / New naming convention
« on: January 08, 2012, 11:18:35 am »
Quote
functions and public variables use the camelCase notation

So the class names are still the same, right?

486
Graphics / Is it possible to crop a text?
« on: January 07, 2012, 05:53:04 pm »
Is it possible to draw e.g. only the top part of a text in SFML2?

487
General / Problem with sequencing events
« on: January 07, 2012, 05:02:08 pm »
Are u really sure that the code doesn't hang after the loop?
I tried the code and it didn't hang.

488
Graphics / Problems Making Multiple RenderWindows Work
« on: January 03, 2012, 05:43:23 pm »
If you use "if" then you will only handle ONE event per frame. When using "while" you will handle ALL events of the window and then continue with drawing.

Are you first calling Clear, then Draw and then Display?

489
Graphics / Problems Making Multiple RenderWindows Work
« on: January 03, 2012, 05:05:01 pm »
After a quick look I notice two things:

1) Shouldn't u use while instead of if at the GetEvent functions?
2) First call Clear and then Display

490
Graphics / Text.GetLocalBounds ignores spaces at the beginning and end?
« on: January 03, 2012, 04:55:59 pm »
When I fill a sf::Text with a string that starts or ends with spaces then the GetLocalBounds and GetGlobalBounds functions don't return the correct width.

Here is an example code:
Code: [Select]
sf::Text text("     test     ");
float Width = text.GetGlobalBounds().Width;

Width will be 49 (with the default font).
This is only the width of the "test", so the spaces are ignored.
The width should be something like 127 (this is what FindCharacterPosition returned).

491
Graphics / Calling SetScale inside Render function
« on: December 31, 2011, 08:08:00 pm »
It took some time to get used to the new Draw function but I solved my problem now by using the RenderStates.

Thanks for the quick response you gave me.

492
Graphics / Calling SetScale inside Render function
« on: December 31, 2011, 07:01:55 pm »
I just downloaded the latest snapshot and I changed my code a little bit (the class is now also derived from sf::Transformable), but the problem is still the same.

Code: [Select]
void Draw(sf::RenderTarget& target, sf::RenderStates states) const
{
    SetScale(4, 4);
}

When using these lines I still get this error: "passing ‘const Object’ as ‘this’ argument of ‘void sf::Transformable::SetScale(float, float)’ discards qualifiers"
I am using Code::Blocks with gcc v4.5.2

I do understand what the error means, I am asking if there is a workaround.

493
Graphics / Calling SetScale inside Render function
« on: December 31, 2011, 04:46:35 pm »
Suppose I have a class derived from sf::Drawable.
Is there an easy way to change the scale inside the Render function?

This would be the code to create, scale and draw the object:
Code: [Select]
Object obj;
obj.Scale(2, 2);
window.Draw(obj);

And this is where the problem lies:
Code: [Select]
void Object::Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
    // I want to change the scale here!
    SetScale(4, 4);
}

I have found a way to do this by using a second class also derived from sf::Drawable and let that class take care of the drawing.
But I was wondering if there isn't an easier way to accomplish this.

I am using SFML2.

494
Graphics / How to center sf::Text (SFML2)
« on: September 06, 2011, 05:04:09 pm »
I couldn't find a function that calculates the size of one character, but I finally found my solution in the code from sf::Text::UpdateRect.

I will post my code here in case someone needs the same function.
Code: [Select]
size_t CharacterSize = Text.GetCharacterSize();
sf::Font Font = Text.GetFont();
std::string String = Text.GetString().ToAnsiString();
bool bold = (Text.GetStyle() & sf::Text::Bold);
size_t MaxHeight = 0;

for (size_t x=0; x<Text.GetString().GetSize(); ++x)
{
    sf::Uint32 Character = String.at(x);

    const sf::Glyph& CurrentGlyph = Font.GetGlyph(Character, CharacterSize, bold);

    size_t Height = CurrentGlyph.Bounds.Height;

    if (MaxHeight < Height)
        MaxHeight = Height;
}

sf::FloatRect rect = Text.GetRect();

rect.Left = (TextureNormal.GetWidth() / 2.0f) - (rect.Width / 2.0f);
rect.Top = (TextureNormal.GetHeight() / 2.0f) - (MaxHeight/2.0f) - (rect.Height-MaxHeight) + ((rect.Height-CharacterSize)/2.0f);

Text.SetPosition(rect.Left, rect.Top);


EDIT: The text was drawn too high but I have solved it and changed it in the code.

495
Graphics / How to center sf::Text (SFML2)
« on: September 05, 2011, 08:46:44 pm »
Thanks, I will try that tomorrow.

Pages: 1 ... 31 32 [33] 34
anything