简体   繁体   English

如何在Pebble C中为TextLayer设置动画?

[英]How to animate a TextLayer in Pebble C?

i started recently coding my first Watchface, but not i can't get it to animate an TextLayer. 我最近开始编码我的第一个Watchface,但不是我无法使它成为TextLayer的动画。

There is a tutorial for animating layers here but i don't know how to modify this to animate TextLayers. 没有为动画层的教程在这里 ,但我不知道如何修改这个动画TextLayers。

I tried it, but then the layer is animated and the text is gone: 我尝试了一下,但是随后该层被设置了动画并且文本消失了:

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

Thanks for your help 谢谢你的帮助

Here's a complete example app that shows a text layer animation: 这是显示文本层动画的完整示例应用程序:

#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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM