对时间取模以获得秒、分钟、小时等
我正在尝试构建一个倒计时,它有四个部分:
显示如下:
0 0 : 0 0
十分钟 分钟 : 十秒 秒
我已经让 _secs 在下面工作,_tensecs 上升到 9,这不好。
int seconds;
int _secs;
int _tensecs;
int _mins;
int _tenmins;
-(void) tick: (ccTime) dt
{
seconds++;
_secs = seconds % 10;
_tensecs = (seconds / 10) % 10; // wrong
_mins = seconds // ??
_m_tenminsins = seconds // ??
}
Im trying to build a countdown, which has four sections:
to be displayed like this:
0 0 : 0 0
tenminutes minutes : tenseconds seconds
Ive got the _secs working below, the _tensecs goes up to 9 which is no good.
int seconds;
int _secs;
int _tensecs;
int _mins;
int _tenmins;
-(void) tick: (ccTime) dt
{
seconds++;
_secs = seconds % 10;
_tensecs = (seconds / 10) % 10; // wrong
_mins = seconds // ??
_m_tenminsins = seconds // ??
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,如果
% 10
给出的值高达9
,您认为需要对什么取模才能获得高达5
的值代码>?Well, if
% 10
gives you values that go up to9
, what do you think you need to modulo by to get values that go up to5
?我不了解 Objective-C,但这应该可以满足您的要求:
假设秒数为正并且您正在倒计时。如果您确实希望它为负数并向上计数,正如您似乎所表明的那样,请更改为:
I don't know Objective-C, but this should do what you want:
This assumes
seconds
is positive and you're counting down. If you really want it negative and counting up, as you seem to be indicating, then change to: