【问题标题】:How to animate a TextLayer in Pebble C?如何在 Pebble C 中为 TextLayer 设置动画?
【发布时间】:2016-06-19 10:06:21
【问题描述】:

我最近开始编写我的第一个 Watchface,但不是我无法让它为 TextLayer 设置动画。

有一个动画层的教程here,但我不知道如何修改它来为 TextLayers 设置动画。

我试过了,但后来图层动画了,文字不见了:

s_box_animation = property_animation_create_layer_frame(text_layer_get_layer(timeLayer), &start, &finish);

感谢您的帮助

【问题讨论】:

    标签: pebble-sdk cloudpebble


    【解决方案1】:

    这是一个显示文本层动画的完整示例应用:

    #include <pebble.h>
    
    static Window *window;
    static TextLayer *text_layer;
    static PropertyAnimation *text_property_animation;
    
    static void trigger_animation() {
      // Set start and end
      GRect from_frame = layer_get_frame(text_layer_get_layer(text_layer));
      GRect to_frame = GRect(10, 10, 50, 50);
    
      // Create the animation
      text_property_animation = property_animation_create_layer_frame(text_layer_get_layer(text_layer), &from_frame, &to_frame);
    
      // Configure the animation, these are optional
      animation_set_duration((Animation*) text_property_animation, 1000); // milliseconds
      animation_set_delay((Animation*) text_property_animation, 250); // milliseconds
      animation_set_curve((Animation*) text_property_animation, AnimationCurveEaseInOut);
    
      // Schedule to occur ASAP with default settings
      animation_schedule((Animation*) text_property_animation);
    }
    
    static void window_load(Window *window) {
      Layer *window_layer = window_get_root_layer(window);
      GRect bounds = layer_get_bounds(window_layer);
    
      text_layer = text_layer_create((GRect) { .origin = { 0, 72 }, .size = { bounds.size.w, 20 } });
      text_layer_set_background_color(text_layer, GColorBlack);
      text_layer_set_text_color(text_layer, GColorWhite);
      text_layer_set_text(text_layer, "Hello World");
      text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(text_layer));
    
      trigger_animation();
    }
    
    static void window_unload(Window *window) {
      text_layer_destroy(text_layer);
    }
    
    static void init(void) {
      window = window_create();
      window_set_window_handlers(window, (WindowHandlers) {
        .load = window_load,
        .unload = window_unload,
      });
      window_stack_push(window, true);
    }
    
    static void deinit(void) {
      window_destroy(window);
    }
    
    int main(void) {
      init();
      app_event_loop();
      deinit();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多