Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
if e is your Accelerometer.EVENT, e.accelerationX, e.accelerationY and e.accelerationZ will change value as the iPad is rotated, pitched and yawed where I use those terms as if the iPad's screen were an airplane facing the user.
In the shorthand below, I use rotationX for the pitch of the iPad, rotationY would be yaw and rotationZ is the iPads rotation.
If you have trouble visualizing all that, create a test fla (if you have Flash CS6) and test. If you don't have Flash CS6, you will need to use a textfield to see the results of your iPad manipulations.
accelerationY: 1 -> 0 as rotationX: 0 -> -90
accelerationX: 1 -> 0 -> -1 as rotationZ: -90 -> 0 -> 90
Find more inspiration, events, and resources on the new Adobe Community
Explore Now