2016-02-04 90 views
0

我可以使用sf :: time类进行循环,因为当我尝试执行此操作时,程序崩溃了。使用sf进行循环::时间

while(time.asSeconds() <= 10.0f) 

这是我用于sf :: Time类的while循环。

+0

你在这里是否缺少一些代码?你的代码意味着什么? – alcedine

+0

对不起,我的代码应该是一个Astroid游戏,我试图在游戏中获得射击meachanic。代码的其余部分是。 void Bullet :: Shoot(){ \t sf :: Time time; \t sf ::时钟; \t time = clock.getElapsedTime(); (3.14159265 * bullet.getRotation()/ 180)* 10,cos(3.14159265 * bullet.getRotation()/ 180)* while(time.asSeconds()<= 10.0f){ \t \t * 10); \t} } –

回答

0

编辑:

sf::Clock clock; // Initializing clock starts counting time. 
while(someCondition) 
{ 
    sf::Time time = clock.getElapsedTime(); 
    //It's going to execute do something() until time is higher than 10.0f 
    while(time.asSeconds() <= 10.0f) 
    { 
     //we need this to ensure that we won't fall into the infinite loop 
     time = clock.getElapsedTime(); 
     do something() 
     //Optional: clock.restart(); If you want your code to be executed every x seconds. 
    } 
} 

首先,你必须创建SF ::时钟变量,然后抓住从时钟SF ::时间变化的时间。