Pebble:如何创建自定义动画?
Pebble: How to create a custom animation?
我在 Pebble 上实现自定义动画时遇到问题。网上真的没有任何教程可以参考,我唯一能找到的是官方的 Pebble 教程:https://developer.pebble.com/guides/pebble-apps/display-and-animations/property-animations/#writing-custom-animation-types
这是我项目代码的一部分:
static Animation *large_pin_animation;
static void anim_update_handler(Animation *animation, const AnimationProgress progress) {
APP_LOG(APP_LOG_LEVEL_INFO, "%d", (int)progress);
}
static void window_load(Window *window) {
large_pin_animation = animation_create();
animation_set_duration(large_pin_animation, 1000);
animation_set_delay(large_pin_animation, 0);
AnimationImplementation anim_implementation = (AnimationImplementation) {
.update = anim_update_handler
};
animation_set_implementation(large_pin_animation, &anim_implementation);
}
当我调用 animation_schedule(large_pin_animation);
时,应用程序崩溃,Pebble 日志没有帮助(它说应用程序错误,所以是某种段错误)。有什么我想念的吗?
问题是 anim_implementation
变量的范围。它应该在声明动画的地方声明,否则在 window_load
之后它超出范围并被释放,所以在我试图 运行 动画的另一个函数中,它不知道anim_implementation
是什么了。
我遇到的另一个问题是,为了多次 运行 动画,我不得不重新创建动画。所以,最后我把所有的动画东西放在一个单独的函数中:
static Animation *large_pin_animation;
static AnimationImplementation anim_implementation;
static void anim_update_handler(Animation *animation, const AnimationProgress progress) {
APP_LOG(APP_LOG_LEVEL_INFO, "%d", (int)progress);
}
static void animate_large_pin() {
large_pin_animation = animation_create();
animation_set_duration(large_pin_animation, 1000);
animation_set_delay(large_pin_animation, 0);
anim_implementation = (AnimationImplementation) {
.update = anim_update_handler
};
animation_set_implementation(large_pin_animation, &anim_implementation);
animation_schedule(large_pin_animation);
}
我在 Pebble 上实现自定义动画时遇到问题。网上真的没有任何教程可以参考,我唯一能找到的是官方的 Pebble 教程:https://developer.pebble.com/guides/pebble-apps/display-and-animations/property-animations/#writing-custom-animation-types
这是我项目代码的一部分:
static Animation *large_pin_animation;
static void anim_update_handler(Animation *animation, const AnimationProgress progress) {
APP_LOG(APP_LOG_LEVEL_INFO, "%d", (int)progress);
}
static void window_load(Window *window) {
large_pin_animation = animation_create();
animation_set_duration(large_pin_animation, 1000);
animation_set_delay(large_pin_animation, 0);
AnimationImplementation anim_implementation = (AnimationImplementation) {
.update = anim_update_handler
};
animation_set_implementation(large_pin_animation, &anim_implementation);
}
当我调用 animation_schedule(large_pin_animation);
时,应用程序崩溃,Pebble 日志没有帮助(它说应用程序错误,所以是某种段错误)。有什么我想念的吗?
问题是 anim_implementation
变量的范围。它应该在声明动画的地方声明,否则在 window_load
之后它超出范围并被释放,所以在我试图 运行 动画的另一个函数中,它不知道anim_implementation
是什么了。
我遇到的另一个问题是,为了多次 运行 动画,我不得不重新创建动画。所以,最后我把所有的动画东西放在一个单独的函数中:
static Animation *large_pin_animation;
static AnimationImplementation anim_implementation;
static void anim_update_handler(Animation *animation, const AnimationProgress progress) {
APP_LOG(APP_LOG_LEVEL_INFO, "%d", (int)progress);
}
static void animate_large_pin() {
large_pin_animation = animation_create();
animation_set_duration(large_pin_animation, 1000);
animation_set_delay(large_pin_animation, 0);
anim_implementation = (AnimationImplementation) {
.update = anim_update_handler
};
animation_set_implementation(large_pin_animation, &anim_implementation);
animation_schedule(large_pin_animation);
}