mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Added fallback support for the web on the SpriteBatch API (#612)
* Added fallback support for the web on the `SpriteBatch` API * Refactored the SpriteBatch class
This commit is contained in:
committed by
GitHub
parent
c462dd6913
commit
33f61d2bab
@ -1,5 +1,6 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame/extensions/vector2.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/sprite_batch.dart';
|
||||
@ -20,19 +21,19 @@ class MyGame extends BaseGame {
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
spriteBatch = await SpriteBatch.withAsset('boom3.png');
|
||||
spriteBatch = await SpriteBatch.load('boom3.png');
|
||||
|
||||
spriteBatch.add(
|
||||
rect: const Rect.fromLTWH(128 * 4.0, 128 * 4.0, 64, 128),
|
||||
offset: const Offset(200, 200),
|
||||
source: const Rect.fromLTWH(128 * 4.0, 128 * 4.0, 64, 128),
|
||||
offset: Vector2.all(200),
|
||||
color: Colors.greenAccent,
|
||||
scale: 2,
|
||||
rotation: pi / 9.0,
|
||||
anchor: const Offset(64, 64),
|
||||
anchor: Vector2.all(64),
|
||||
);
|
||||
|
||||
spriteBatch.addTransform(
|
||||
rect: const Rect.fromLTWH(128 * 4.0, 128 * 4.0, 64, 128),
|
||||
source: const Rect.fromLTWH(128 * 4.0, 128 * 4.0, 64, 128),
|
||||
color: Colors.redAccent,
|
||||
);
|
||||
|
||||
@ -44,8 +45,8 @@ class MyGame extends BaseGame {
|
||||
final x = r.nextInt(size.x.toInt()).toDouble();
|
||||
final y = r.nextInt(size.y ~/ 2).toDouble() + size.y / 2.0;
|
||||
spriteBatch.add(
|
||||
rect: Rect.fromLTWH(sx, sy, 128, 128),
|
||||
offset: Offset(x - 64, y - 64),
|
||||
source: Rect.fromLTWH(sx, sy, 128, 128),
|
||||
offset: Vector2(x - 64, y - 64),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user