Created
March 7, 2022 17:21
-
-
Save Kurogoma4D/ce1c36bd05a9c3fcf852462acb561a64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:ui' as ui; | |
import 'package:flutter/material.dart'; | |
import 'package:graphx/graphx.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const Home(), | |
); | |
} | |
} | |
class Home extends StatelessWidget { | |
const Home({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: SceneBuilderWidget( | |
builder: () => SceneController( | |
back: SimpleShapes(), | |
), | |
child: const SizedBox.expand(), | |
), | |
), | |
); | |
} | |
} | |
Future<ui.Image> getImage(String path) async { | |
final byteData = await rootBundle.load(path); | |
return await decodeImageFromList(byteData.buffer.asUint8List()); | |
} | |
class SimpleShapes extends GSprite { | |
final particle = GSimpleParticle(); | |
@override | |
void addedToStage() { | |
super.addedToStage(); | |
getImage('assets/small.png').then((image) { | |
final texture = GTexture.fromImage(image); | |
final emitter = GSimpleParticleSystem() | |
..x = 400 | |
..y = 200 | |
..initialColor = 0xff00ff | |
..initialScale = 0.4 | |
..endAlpha = 0.2 | |
..initialScale = 1.0 | |
..endScale = 0.1 | |
..emissionDelay = 0.0 | |
..initialAcceleration = 0.12 | |
..dispersionXVariance = 240 | |
..dispersionYVariance = 240 | |
..dispersionAngle = 2.0 | |
..dispersionAngleVariance = 80 | |
..emit = true | |
..energy = 12.0 | |
..texture = texture; | |
emitter.setup(40); | |
addChild(emitter..init()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment