flutter_flame_codex
flutter_flame_codex
s ic
Game Development
with Flutter and Flame
By
Afzal Ali
Preface
Index
Sprite ............................................................................................................... 3
SpriteComponent .................................................................................. 4
SpriteAnimation ....................................................................................... 5
SpriteAnimationComponent .......................................................... 6
SpriteAnimationGroupComponent ........................................... 7
Collision Detection ................................................................................. 8
Keyboard Input ........................................................................................ 9
Touch Input - Joystick ........................................................................ 10
Effects ............................................................................................................. 11
Sprite
Sprite is an Image that can be rendered in the Canvas. It is
used to represent a character, item, or other visual element
in the game.
Sprite may
represent entire
image or part of
the image based
on region defined.
bird.png
To load specific
var birdSprite = await Sprite.load(
part of the image,
‘bird.png’,
srcPosition: Vector2(50, 0), you can define
srcSize: Vector2(50, 50), position and size
); that you want to
target.
(50,0)
50
50
SpriteComponent
SpriteComponent renders the sprite on the canvas. It
manages the size, position and other Layout properties.
(0,0)
MyGame
(100,300)
add(birdComponent);
SpriteAnimation.fromAsepriteData(image, jsonData);
It creates animation from Aseprite JSON data.
SpriteAnimation.fromFrameData(image, data);
It Creates animation with image which we can load from
Sprite, and data which defines frame details and interval
SpriteAnimationData.sequenced(
amount: 6,
amountPerRow: 3, 50
stepTime: 0.05, 50
SpriteAnimation.variableSpriteList(sprites, stepTimes:
stepTimes);
It Creates animation with List<Sprites> and different
interval can be defined by stepTimes.
@override
void onCollision(intersectionPoints, other) {
if (other is Drone) {
current = BirdState.falling;
}
return super.onCollision(intersectionPoints, other);
}
Keyboard Input
Flame engine supports both keyboard input and touch
input to interact with game objects and perform action.
@override
bool onKeyEvent(event, keysPressed) {
var isSpace =
keysPressed.contains(LogicalKeyboardKey.space);
if(isS
pace){
//Shoot
}
return super.onKeyEvent(event, keysPressed);
}
Touch Input - Joystick
Joystick movement is also very common in character
playing games, add DragCallbakcs in your FlameGame to
get drag updates.
switch (joystick.direction){
case JoystickDirection.up:
bird.moveUp();
case JoystickDirection.down:
bird.moveDown();
}
Effects
Effects can be applied on components to change their
properties over time which gives animated effect.
add(opacityEffect);
.
.
}
100 ms
Time to Action
Thank you for staying with me till end, I would like you to
join on codexdev.net for more updates on Flutter and
Game Development.