自方法调用以来,我需要时间。基本上,如果我调用方法1次并等待50秒然后再次调用它,那么我需要能够获得50秒。我没有调用两个精灵碰撞时自动被调用的方法。我该如何实现。
最佳答案
您可以使用静态或全局或成员变量的帮助来存储上次呼叫的时间戳。根据当前时间戳和上次调用时间戳,您可以获取diff并获取自上次方法调用以来的时间。
由于方法属于一类,因此可以将其存储在对象中,并在每次调用它时进行更新。
@interface Myclass:NSObject
{
int64_t timestamp; //Initialize it with the creation of the object or 0.
}
-(void) myMethod
@end
@implementation Myclass
-(void) myMethod
{
//take diff from last timestamp
int64_t ts = get_current_time_stamp();//Implement this yourself
//get diff
timestamp = ts;
}
@end
关于ios - 获取自上次方法调用以来的时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29359778/