Flixel Power Tools FlxControl
Back to the Flixel Power Tools
This class makes it painfully easy to quickly set-up controls for your game, and then it takes control over the motion and physics of your player sprite. Acceleration, deceleration, jumping, firing, gravity, cursor keys, WASD, IJKL, heck anything you like! It can cope with a lot. 2 players on the same keyboard? No problem, it’s just 2 lines of code!
It might seem strange to make a class for keyboard controls when Flixel makes it so easy anyway, but I promise this will save a lot of repeat code and maybe even add some features you always wanted?!
Screen Shot
Code Example
1 2 3 4 5 6 7 8 9 10 |
// The player sprite will accelerate and decelerate smoothly FlxControl.create(player, FlxControlHandler.MOVEMENT_ACCELERATES, FlxControlHandler.STOPPING_DECELERATES); // Enable cursor keys, but only the left and right ones FlxControl.player1.setCursorControl(false, false, true, true); // Gravity will pull the player down FlxControl.player1.setGravity(0, 400); // All speeds are in pixels per second, the follow lets the player run left/right FlxControl.player1.setMovementSpeed(400, 0, 100, 200, 400, 0); |
Recent Flixel Power Tool Posts
- Flixel Power Tools v1.9 Released
- Flixel Power Tools v1.8 Released - Let's get clicky
- Flixel Power Tools v1.7 - Kaboom!
- Flixel Power Tools v1.6 released including FlxControl
- Flixel Power Tools v1.5 - A monster of an update!
- FlxScreenGrab and FlxScrollZone added to Flixel Power Tools
- Flixel Power Tools v1.3 - Now Flixel 2.5 compatible!
- FlxHealthBar added to Flixel Power Tools
3 Responses
Leave a commentMake yourself heard
FPT Classes
Hire Us
All about Photon Storm and our
HTML5 game development services
Recent Posts
OurGames
Filter our Content
- ActionScript3
- Art
- Cool Links
- Demoscene
- Flash Game Dev Tips
- Game Development
- Gaming
- Geek Shopping
- HTML5
- In the Media
- Phaser
- Phaser 3
- Projects
Brain Food
The control handler seems to only take into account the bounds of the sprite when a movement key is being pressed. This means that if I have a sprite with acceleration/deceleration, when I push the sprite to the boundary and let go of the key, the sprite is freely allowed past the boundary and doesn’t return until I press a key again.
If this is the intended behavior, it doesn’t seem to match the setBounds() description, “Limits the sprite to only be allowed within this rectangle. If its x/y coordinates go outside it will be repositioned back inside.”
For my purposes, I’m going to have it check on update().
How do you add extra keys?
and how do you add extra functions to these keys?
regards