C 卵石-秒针在23秒时造成碰撞
我想为我的鹅卵石写一个模拟手表,所以我决定开始制作一个秒针的动画,只是为了确保我明白我在做什么。我已经这样做了,奇怪的是它只在一分钟后0到22秒之间工作。当它计时到23秒时,它就会崩溃,直到下一分钟开始时才能正确启动 我有一个单层占据了整个屏幕,这是更新该层的回调函数:C 卵石-秒针在23秒时造成碰撞,c,pebble-watch,C,Pebble Watch,我想为我的鹅卵石写一个模拟手表,所以我决定开始制作一个秒针的动画,只是为了确保我明白我在做什么。我已经这样做了,奇怪的是它只在一分钟后0到22秒之间工作。当它计时到23秒时,它就会崩溃,直到下一分钟开始时才能正确启动 我有一个单层占据了整个屏幕,这是更新该层的回调函数: void face_layer_update_callback(Layer *me, GContext* ctx) { //set colour graphics_context_set_stroke_color(ct
void face_layer_update_callback(Layer *me, GContext* ctx) {
//set colour
graphics_context_set_stroke_color(ctx, GColorBlack);
time_t now = time(NULL);
struct tm *t = localtime(&now);
int seconds = t->tm_sec;
int hand_length = 50;
GPoint p0 = GPoint(72, 84);
int x, y, z;
z = seconds * 6;
x = hand_length * sin( (PI/180) * z);
y = hand_length * cos( (PI/180) * z);
GPoint p1 = GPoint(72 + x, 84 - y);
graphics_draw_line(ctx, p0, p1);
}
我添加了日志来输出计算值z、x和y,它们正是我所期望的。有人能看出哪里出了问题吗
(顺便说一下,这是在原始卵石上,而不是卵石时间。)
更新:在Thomas的评论之后,我添加了更多日志记录,现在代码如下所示:
void face_layer_update_callback(Layer *me, GContext* ctx) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "Start of callback routine");
//set colour
graphics_context_set_stroke_color(ctx, GColorBlack);
time_t now = time(NULL);
struct tm *t = localtime(&now);
int seconds = t->tm_sec;
APP_LOG(APP_LOG_LEVEL_DEBUG, "seconds: %d", seconds);
int hand_length = 50;
GPoint p0 = GPoint(72, 84);
int x, y;
int degrees;
degrees = seconds * 6;
float radians = (PI/180) * degrees;
APP_LOG(APP_LOG_LEVEL_DEBUG, "About to do trigonometry: degrees = %d", degrees);
x = hand_length * sin(radians);
APP_LOG(APP_LOG_LEVEL_DEBUG, "Done sin, about to do cos");
y = hand_length * cos(radians);
APP_LOG(APP_LOG_LEVEL_DEBUG, "x = %d", x);
APP_LOG(APP_LOG_LEVEL_DEBUG, "y = %d", y);
APP_LOG(APP_LOG_LEVEL_DEBUG, "End of hand: %d, %d", 72 + x, 84 - y);
GPoint p1 = GPoint(72 + x, 84 - y);
APP_LOG(APP_LOG_LEVEL_DEBUG, "About to draw hand");
graphics_draw_line(ctx, p0, p1);
日志显示:
[INFO ] D analogueface.c:11 Start of callback routine
[INFO ] D analogueface.c:20 seconds: 21
[INFO ] D analogueface.c:32 About to do trigonometry: degrees = 126
[INFO ] D analogueface.c:35 Done sin, about to do cos
[INFO ] D analogueface.c:38 x = 40
[INFO ] D analogueface.c:39 y = -29
[INFO ] D analogueface.c:40 End of hand: 112, 113
[INFO ] D analogueface.c:44 About to draw hand
[INFO ] D analogueface.c:11 Start of callback routine
[INFO ] D analogueface.c:20 seconds: 22
[INFO ] D analogueface.c:32 About to do trigonometry: degrees = 132
[INFO ] D analogueface.c:35 Done sin, about to do cos
[INFO ] D analogueface.c:38 x = 37
[INFO ] D analogueface.c:39 y = -33
[INFO ] D analogueface.c:40 End of hand: 109, 117
[INFO ] D analogueface.c:44 About to draw hand
[INFO ] D analogueface.c:11 Start of callback routine
[INFO ] D analogueface.c:20 seconds: 23
[INFO ] D analogueface.c:32 About to do trigonometry: degrees = 138
我试图记录弧度值,但无法在日志中格式化
(为试图在评论中添加不应该出现的内容而道歉)。你知道哪一行是有罪的吗?22秒和23秒的数值是多少?罪过线似乎是罪过计算线。我做了一些更改并添加了更多日志记录:@Thomas:analogueface.c:11开始回调例程
analogueface.c:20秒:22
analogueface.c:32即将做三角学:度=132
analogueface.c:35完成,即将做cos
analogueface.c:38 x=37
analogueface.c:39 y=-33
analogueface.c:44即将画手
analogueface.c:11开始回调例程
analogueface.c:20秒:23
analogueface.c:32即将做三角学:度=138
对这种格式表示歉意我需要找出如何在评论…请编辑问题:)@Thomas我已经做了-为新手错误道歉。:)