Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Accelerometer Help PLEASE

New Here ,
Mar 11, 2013 Mar 11, 2013

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

TOPICS
ActionScript
343
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 11, 2013 Mar 11, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines