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

Pages: [1]
1
General / Re: Simplle way to implement an input field
« on: April 09, 2012, 03:59:36 pm »
Thanks both of you! I'll check those libraries out ;).

2
General / Simplle way to implement an input field
« on: April 09, 2012, 03:35:12 pm »
Hello again!

What's the simplest way to implement an input field similar to those used in windows applications
(like the adress bar of your browser)?

I'd like to use this in a screen to be able to write a text (like a typical chat would look like in a game).
Is there a way without having to program every tiny aspect of how such bars behave so I don't have to
check for, let's say shift+a to write a capital A and a without shift to write a lower case letter, etc.

I apologize in case this is not a sfml-related question because there's no way to do it with sfml and therefore it doesn't belong here but in that case I'd appreciate some hints.

Thanks in advance,
Trynox

3
General / Re: Time management won't work
« on: April 09, 2012, 12:39:26 pm »
Alright, thanks for your help!

4
General / Re: Time management won't work
« on: April 09, 2012, 12:01:50 pm »
Hello,

thanks for your reply - but this is not what I'm trying to achieve. Sorry for expressing myself not
clearly enough.

I want my program to run on every computer with the same speed regardless of the hardware being
used, which is actually kind of a basic move but I somehow am not able to do it. Not timing it would
make this program run way too fast on my computer.
There's an article on the SFML homepage on how to do it with SFML 1.6:
http://www.sfml-dev.org/tutorials/1.3/window-time.php

But this won't work with SFML2 of course.

Thanks in advance,
CTryn

5
General / Time management won't work
« on: April 09, 2012, 08:37:23 am »
Hello,

for the last few hours I've been trying to resolve a problem regarding the time management in my
SFML2 program. I want to make sure my program runs with the same speed on different computers.

I know there have been plenty of threads about this in the past but the problem is those either
use a function which is not available anymore (getframetime) or they don't go too much into
detail to clarify this matter for me.

Code: [Select]
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>

int main()
{
sf::VideoMode VMode(800, 600, 32);
sf::RenderWindow Window(VMode, "Empty Window");

sf::CircleShape circle;
circle.setRadius(8);
circle.setOutlineColor(sf::Color(0, 100, 100));
circle.setOutlineThickness(3);
circle.setPosition(10, 20);
circle.setFillColor(sf::Color(0, 255, 255));

sf::Clock clock;
clock.restart();

int updateNext = clock.getElapsedTime().asMilliseconds();

int cx, cy;
cx = 10;
cy = 20;

while (Window.isOpen())
{
sf::Event Event;
while (Window.pollEvent(Event))
{
switch (Event.type)
{
case sf::Event::Closed:
Window.close();
break;
default:
break;
}
}

Window.draw(circle);
Window.display();

Window.clear(sf::Color(0, 0, 0));

while (clock.getElapsedTime().asMilliseconds() > updateNext)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
circle.setPosition(cx-=2, cy);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
circle.setPosition(cx+=2, cy);

}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
circle.setPosition(cx, cy-=1);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
circle.setPosition(cx, cy+=1);
}
updateNext += 1/60;
}
}

return EXIT_SUCCESS;
}

I never really understood how these timing functions work.
I know you save the elapsed time since the program started but what time exactly is measured
by the start of each loop?
Code: [Select]
while (clock.getElapsedTime().asMilliseconds() > updateNext)
Shouldn't it be the time until the start of this loop (which would increase after every loop)?
I also don't quite get why this should help limiting the speed at which the loop is executed by
comparing it to the time since the program has started. And why do you add 1/60 to the elapsed
time since the program has started? I do know this is the desired framerate as 1/60 is equal to '60hz'
though.
Then again, the above code doesn't work anyway, so I'm not sure if my above assumptions are correct.

How do I make it work and how exactly does it work?

Thanks in advance,
CTryn

Pages: [1]
anything