Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Using the Accelerometer

Contents

  • Introduction
  • How to Enable the Accelerometer (Stencyl 2.2 and below)
  • Accelerometer Values
  • How to Use the Values

 

Introduction

Some games use an accelerometer to create games a user can control by tilting the device. One famous example is the Labyrinth game.


How to Enable the Accelerometer (Stencyl 2.2 and below)

Note: In Stencyl 3.0 and above, this is no longer necessary. The accelerometer is always enabled.

To enable the accelerometer, click the Settings button...

Settings Button

Then click Mobile> User Input, as shown:

Mobile settings, user input

Set the Accelerometer value to 30 (shown at #3).

Note: The reason we disable the accelerometer by default is because it drains valuable processing time from touch input and can cause that touch input to lag. In Stencyl 3.0, the new engine does not suffer from this behavior, hence why it's always on.

30 FPS suffices for most games. A higher value makes accelerometer control smoother at the expense of a game’s framerate.


Accelerometer Values

You can access accelerometer data through a trio of blocks under the User Input > Mobile category in the Design Mode Palette.

The values of each of these range between -1.0 and 1.0 inclusive. Those values represent how much the device is tilted in a given direction.

For example, an x value of 1 would mean the user is tilting it all the way to the right. An x value of -1 would mean it’s tilted all the way to the left.

Note: The values are flipped for a landscape oriented game. In other words, the values are always relative to portrait orientation and don't automatically flip for a landscape game. See the example below for details.

 

Tip: Do not enable auto-rotation for a game that uses the accelerometer. This will cause the values to flip and generally create a confusing situation.


How to Use the Values

To replicate a basic tilting motion on a landscape-oriented game, create a simple behavior as shown in the image below. You can adjust the value “-70” to another that suits your needs.

Note: The reason why x and y are flipped is because this is for a landscape-oriented game. For a portrait-oriented game, flip the y and x blocks around.

In the Labyrinth demo game’s case, the negative value worked best to produce the type of gameplay we were looking for. Again, try out different values until you find one that works for your game.

Tip: If you find the values to be too sensitive/fidgety, add some code to throw out really low absolute values and require the device to be tilted further than some minimum threshold before responding.


Last Updated: 2013-04-10 by Jon

6622 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
2 Comments
Jon
Most games don't use the Z-axis - it would be triggered by laying the device flat and spinning it around - not practical for most games.
0 1 year, 4 months ago
malospam
Interesting. Maybe some comments on using the z-axis would be good. Much appreciated.
0 1 year, 6 months ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.