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

Controls

Contents

  • Keyboard (Controls)
  • Mouse
  • Mouse over Actor
  • The Cursor
  • Mobile Controls
  • Example: 4 Way Motion
  • The Future


Keyboard (Controls)

Detecting keyboard input works differently in Stencyl than it does in other systems. We use the notion of a Control to make your keyboard controls flexible and easy to remap.

A Control is simply a name that pertains to an action, or a “button” if you will, on a controller.

For example, if we were designing a control scheme for a Mario game, it would look like this.

NES-controller

The same idea applies to Stencyl, through a game’s Controls Page. To set Controls, click the Settings button, shown below, to open that dialog.

Stenyl Settings Button

Next, click the Controls button to view the Controls pane. From there, you tell us the name of the Control and the button it maps to.

Setting up Controls in Stencyl

Now, when you check whether a key is pressed, released or down, instead of checking directly on a certain key (such as spacebar), you check the state of the Control.

stencyl-design-mode-check-keyboard-input

 

Why do we make you go through this? Why can’t you just say the key directly?

- What if you decide to change your control scheme? You’d have to change it everywhere.

- What if you wanted to make your control scheme configurable? That would be a mess. With Controls, you just change what key the Control is mapped to.

Note: To reduce the amount of setup, all Stencyl games come pre-shipped with a default set of controls. You’re free to edit them, delete them, etc.

 

Mouse

Mouse input is detected through 3 different states.

  • Pressed
  • Released
  • Down


Pressed and Released are one-off “events” - they fire once per that action, whereas “down” is a constant state that can be checked.

You can also grab the (x,y) location of the mouse on screen or any recent presses/releases.

stencyl-design-mode-get-mouse-location

 

Mouse over Actor

Similarly, mouse input over an actor involves 4 different states.

  • Pressed on Actor
  • Released on Actor
  • Down on Actor
  • Over Actor

Over Actor is our term for hovering the mouse over the actor.

 

The Cursor

Sometimes, you want to hide the cursor or display a custom cursor. How do you do this?

To show or hide the cursor, use this block.

stencyl-design-mode-hide-mouse-cursor

Mini-Challenge: How would you create a custom cursor? One method is to hide the cursor and create a dummy actor that continually follows the mouse but does not collide with anything.

 

Mobile Controls

We've covered this separately.

  • Accelerometer
  • Virtual Joystick

 

Example: 4 Way Motion

This example shows a simple use-case for Keyboard controls.

Up/Down/Left/Right are pre-defined controls that come with each game - they are not to be mixed up with the actual, literal keys by the same name.

stencyl-design-mode-four-way-motion-example

Mini-Challenges

  • One drawback of this simple approach is that you can walk diagonally. How would you fix this?
  • In this version, the player stops immediately after you lift the keys. Implement a version where the player slows down gradually.

 


The Future

Although abstracting keys is powerful and flexible, some developers have expressed a desire to work with fixed keys. In a future version of Stencyl, we’ll add the ability to choose a key directly, rather than an abstract control.

We’ll also be consolidating Mouse and Touch input into a single set of blocks to simplify the porting process from Web to Mobile.


Summary

  • Detect key events by creating abstract controls and checking the state those controls.
  • Controls let you change the control scheme for your game from one place.

 

Challenge: Button

Create a button that responds to Mouse controls but goes beyond just a one liner "when pressed, do something".

The button should work just like a regular button. Specifically, don’t register a button click unless the gesture was both started and completed on the button.

Food for Thought: Think of scenarios where simply detecting a release would be incorrect.


Challenge: Cutscenes

There’s a nifty block for simulating key presses and releases. It’s useful for creating on-screen buttons in mobile games that can act as if they were physical keyboard buttons.

stencyl-design-mode-simulate-key-press-block

It’s also useful for creating cutscenes. Make a cutscene using this block.



Last Updated: 2012-07-24 by Ceric

23473 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
soumitra
wow!
0 2 months, 4 weeks ago
Jinado
FIRST!
-1 11 months, 2 weeks 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.