Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Image blink when use rotate in event

Hi everyone, I'm having a "problem" with the rotate animation. I'm working on a compass and when I rotate my image, it's blinking. Here is the code :

var t = Ti.UI.create2DMatrix();
var a = Titanium.UI.createAnimation();
t = t.rotate(360 - e.heading.magneticHeading);
a.visible = true;
a.opacity = 1;

I used "visible" and "opacity" because the transform + animate reset (rotate = 0) the image before applying the rotation.

Any ideas ? Thanks for help.

PS : I was only able to try this on my Nexus One (Yes, Android !).

S. Jeremy

— asked November 3rd 2010 by Jeremy Sculfort
  • android
  • blink
  • mobile
  • rotate

2 Answers

  • I had the same problem creating a watch app. I assumed that as I was animating something I should use the animation api, however, this creates an animation that starts and returns to 0 degrees so my watch flickered a lot and the hands appeared to be stuck at 12 o`clock.

    I suspect that your compass flickers with the needle pointing north.

    The solution is to use a transform on an imageview not an animation, below is some code from my watch that should demonstrate.

    var second_hand = Titanium.UI.createImageView({
    function tick() {
        var rot_second = Ti.UI.create2DMatrix();
        currentTime = new Date();
        curdate = currentTime.getDate();
        curday = currentTime.getDay();
        hours = currentTime.getHours();
        minutes = currentTime.getMinutes();
        seconds = currentTime.getSeconds();
        millis = currentTime.getTime() % 1000;
        ticks = Math.floor(millis / 250);
        second_hand_angle = (6 * seconds) + (1.5 * ticks);
        rot_second = rot_second.rotate(second_hand_angle);
        second_hand.transform = rot_second;

    Hope this helps.

    — answered December 2nd 2010 by Derrick Huth
    1 Comment
    • Did you do this on iPhone or Android? Cause transform on my image object on Android does nothing. Nothing in the log too.

      — commented December 17th 2010 by George Marmaridis
  • Wow, 2 years later and this code works perfect! Thanks!

    — answered June 29th 2012 by Andrew Royce
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.