Continuous Rotation
I have my object on the page,
// CREATE pinwheel
//
var t3 = Titanium.UI.create2DMatrix().rotate(0);
var pinwheel = Titanium.UI.createView({
backgroundImage:'images/pinwheel.png',
height:178,
width:261,
top:10,
transform:t3
});
win1.add(pinwheel);
But I need it to rotate continually in the background
4 Answers
-
This is how I spin bitmaps
-
Once you have your animation set up, you can use
setInterval
:setInterval(function() { //do my animation stuff },1000); // this will cause this code block to run every second
-
This has been a tricky one, and may have a transform bug to figure out. My app revolves around getting a controlled spin just right, and it's almost working, but I wish I didn't have to use the animate function. Here's a stripped down summary of what I have:
var clockwise = true; var spinning = true; var spinSpeed = 500; //equivalent to the setInterval ms var spinRotation = 60; var currentRotation = 0; var t = Titanium.UI.create2DMatrix(); var a = Titanium.UI.createAnimation(); var Spinner = Titanium.UI.createImageView({ image: 'images\Spinner.png', canScale:false, top:9, anchorPoint:{x:0.5,y:0.5}, transform:t }); function spinIt() { if(clockwise) { currentRotation += spinRotation; if(currentRotation > 360) currentRotation -= 360; } else { currentRotation -= spinRotation; if(currentRotation < -360) currentRotation += 360; } t = t.rotate(currentRotation); a.transform = t; //a.duration = 0; Spinner.animate(a); if(spinning) { setTimeout(spinIt, spinSpeed); } } if(spinning) { spinIt(); }
So while this works to spin it, it's got a major flaw that makes it essentially unusable for what it is… With each iteration, it flickers to the rotation 0 point, then rotates it, so it looks very jerky/choppy. I've tried a bunch of variations, read through all the related posts, and nothing worked well. I don't even want to do it with the Animation function since that would just slow down the code at the higher speeds, and I just want to transform it immediately with each turn, but apparently there's no built in way to do that I've found. Was much easier in ActionScript where I could just do the rotate directly on the MovieClip. Does anyone have a fix for this? I really don't have an application without this spinning smoothly. Thanks.
-
Now I have just about everything else in my Sacred Geometry app working, readied for v1.0 release, except this rotate bug. I will offer a free commercial version of my SacredG.com Mesmerizing Meditation App as a humble reward to whoever can help me get this spinning right.. Thanks guys, Titanium is a really great language to develop with, and I'm impressed by how easily everything flows together. Can't wait for the future versions…