Accelerometer Help PLEASE
Hey All, I'm a total newby to Flash and Actionscripting and am still trying to get my head around it all. I'm trying to create images that essentially move from side to side when I tilt my iPad. My aim is to have layered images, foreground, middle, and background, so that when you tilt the iPad the various layers move to reveal more of the image, with the background layer moving more than the foreground. I'm basically trying to create a sense of depth. And of course I want the images to stop moving when they get to their edge and not fall away to nothingness.
What I have are images 1400px wide and want them to move sideways on my iPad, so 1024 px. The registration points of the movieclips are all in the middle. How do I get this to work?
Here is what I have (the numbers are all guess work, I figure if I play around with it I'll get something to work
). All of this code is grabbed from the internet :
package {
import flash.display.MovieClip;
import flash.events.AccelerometerEvent;
import flash.sensors.Accelerometer;
public class Main extends MovieClip {
private var acc:Accelerometer;
public function Main() {
if(Accelerometer.isSupported)
{
var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
back.x -= event.accelerationX * 30;
if (back.x > (1400 - back.width / 4.5))
{
back.x = 1400 - back.width /4.5;
}
if (back.x < (-700 + back.width / 4.5))
{
back.x = -700 + back.width / 4.5;
}
}
}
}
}
}
What I have happening with this is the MovieClip (called 'back') stops sliding off screen about 2/3 of the way when I tilt the iPad down to the lift, but when I tilt the iPad down to the right it slides all the way off the screen. The 'back' movieclip is set at -188 on the x (in it's properties, not in scene) so as to centre the clip.
Can someone please help me to understand how I get this to work. I want to tilt my iPad either left or right and have the movieclip stop moving when it reaches it's exact width.
MANY thanks in advance for any help
,
Kev
