2016-02-26 29 views
0

我在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);應用程序崩潰,並且卵石日誌沒有幫助(它說應用程序故障,所以某種段錯誤)。有什麼我失蹤?

回答

0

問題是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); 
}