- Version: 0.1.0
- Type: Input
- Author: Benjamin D. Richards for Kiwi.js Team
- Website: www.kiwijs.org
- Kiwi.js Version Last Tested: 1.1.1
0.1.0
- Plugin created
README.md - This readme file. .gitignore - General gitignore stuff. gruntfile.js - Build file package.json - Node packages required for the grunt build along with information for the gruntfile to use when building. docs/ - Documentation generated by yuidocs. examples/ - Examples of the in-app purchase plugin in action. src/ - The source files for the plugin.
This plugin allows you to filter inputs in your KiwiJS games.
Download the plugin repo from GitHub. Get the plugin file from src/pointer-filter-[version].js
, or the minified file from src/pointer-filter-[version].min.js
. You may wish to place this in a plugins
folder to keep your project neat.
Load the plugin file in your html, after loading KiwiJS but before your game.
<script src="js/lib/kiwi.js"></script>
<script src="js/plugins/pointer-filter-0.1.0.js"></script>
<script src="js/myGame.js"></script>
Within your game, create a Kiwi.Plugins.PointerFilter.PointerFilter
object. We suggest you do this in the create
method of a state, as the object requires the game to be booted in order to access all necessary data. We also suggest you attach the object to the game, rather than a state, as you may lose direct access to the object after a state transition.
// This PointerFilter targets the mouse, which is pointer 10
this.game.pointerFilterMouse = new Kiwi.Plugins.PointerFilter.PointerFilter(
this.game.input.pointers[ 10 ] );
You may define filters using empty functions on the PointerFilter object. Once you have defined your filters, you may activate them by setting the respective flag to true
. Note that you must define the filter before setting the flag, or it will not execute. Whenever you set the flag to true, it will read the current filter method.
Your filter should have an event
parameter. This contains mutable versions all the normal mouse event values. However, it is easiest to use the x
and y
properties we have provided; these map directly to the game area.
// Add a filter
this.game.pointerFilterMouse.onMove = function( event ) {
event.x = this.game.stage.width - event.x;
event.y = this.game.stage.height - event.y;
};
this.game.pointerFilterMouse.filterMove = true;
// Disable the filter
this.game.pointerFilterMouse.filterMove = false;
A note on scope: Filters execute on the Pointer object. The object has a this.game
property which can access your game object and other parts of the code.
You may filter on move, start, stop, and wheel events. These have the following flags:
filterMove
filterStart
filterStop
filterWheel
And the following methods:
onMove
onStart
onStop
onWheel
Note that wheel events only occur on a mouse.
We hope you enjoy this plugin. If you have any questions, suggestions, or bugs, please contact us at www.kiwijs.org.