Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
153e1bb9
Commit
153e1bb9
authored
May 06, 2016
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes to particle system API (#3762)
parent
01978d98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
46 deletions
+64
-46
fitness_demo.dart
examples/material_gallery/lib/demo/fitness_demo.dart
+1
-2
particle_system.dart
packages/flutter_sprites/lib/src/particle_system.dart
+63
-44
No files found.
examples/material_gallery/lib/demo/fitness_demo.dart
View file @
153e1bb9
...
...
@@ -7,7 +7,6 @@ import 'dart:math' as math;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_sprites/flutter_sprites.dart'
;
import
'package:vector_math/vector_math_64.dart'
as
vec
;
ImageMap
_images
;
SpriteSheet
_sprites
;
...
...
@@ -581,7 +580,7 @@ class _FireworksNode extends NodeWithSize {
speedVar:
50.0
,
startSize:
1.0
,
startSizeVar:
0.5
,
gravity:
new
vec
.
Vector2
(
0.0
,
30.0
),
gravity:
const
Offset
(
0.0
,
30.0
),
colorSequence:
new
ColorSequence
.
fromStartAndEndColor
(
startColor
,
endColor
)
);
system
.
position
=
new
Point
(
randomDouble
()
*
1024.0
,
randomDouble
()
*
1024.0
);
...
...
packages/flutter_sprites/lib/src/particle_system.dart
View file @
153e1bb9
...
...
@@ -41,6 +41,49 @@ class _ParticleAccelerations {
/// number of particles can never exceed the [maxParticles] limit.
class
ParticleSystem
extends
Node
{
ParticleSystem
(
this
.
texture
,
{
this
.
life
:
1.5
,
this
.
lifeVar
:
1.0
,
this
.
posVar
:
Point
.
origin
,
this
.
startSize
:
2.5
,
this
.
startSizeVar
:
0.5
,
this
.
endSize
:
0.0
,
this
.
endSizeVar
:
0.0
,
this
.
startRotation
:
0.0
,
this
.
startRotationVar
:
0.0
,
this
.
endRotation
:
0.0
,
this
.
endRotationVar
:
0.0
,
this
.
rotateToMovement
:
false
,
this
.
direction
:
0.0
,
this
.
directionVar
:
360.0
,
this
.
speed
:
100.0
,
this
.
speedVar
:
50.0
,
this
.
radialAcceleration
:
0.0
,
this
.
radialAccelerationVar
:
0.0
,
this
.
tangentialAcceleration
:
0.0
,
this
.
tangentialAccelerationVar
:
0.0
,
this
.
maxParticles
:
100
,
this
.
emissionRate
:
50.0
,
this
.
colorSequence
,
this
.
alphaVar
:
0
,
this
.
redVar
:
0
,
this
.
greenVar
:
0
,
this
.
blueVar
:
0
,
this
.
transferMode
:
TransferMode
.
plus
,
this
.
numParticlesToEmit
:
0
,
this
.
autoRemoveOnFinish
:
true
,
Offset
gravity
})
{
this
.
gravity
=
gravity
;
_particles
=
new
List
<
_Particle
>();
_emitCounter
=
0.0
;
// _elapsedTime = 0.0;
if
(
_gravity
==
null
)
_gravity
=
new
Vector2
.
zero
();
if
(
colorSequence
==
null
)
colorSequence
=
new
ColorSequence
.
fromStartAndEndColor
(
new
Color
(
0xffffffff
),
new
Color
(
0x00ffffff
));
}
/// The texture used to draw each individual sprite.
Texture
texture
;
...
...
@@ -108,7 +151,21 @@ class ParticleSystem extends Node {
double
tangentialAccelerationVar
;
/// The gravity vector of the particle system.
Vector2
gravity
;
Offset
get
gravity
{
if
(
_gravity
==
null
)
return
null
;
return
new
Offset
(
_gravity
.
x
,
_gravity
.
y
);
}
Vector2
_gravity
;
void
set
gravity
(
Offset
gravity
)
{
if
(
gravity
==
null
)
_gravity
=
null
;
else
_gravity
=
new
Vector2
(
gravity
.
dx
,
gravity
.
dy
);
}
/// The maximum number of particles the system can display at a single time.
int
maxParticles
;
...
...
@@ -157,45 +214,6 @@ class ParticleSystem extends Node {
..
filterQuality
=
FilterQuality
.
low
..
isAntiAlias
=
false
;
ParticleSystem
(
this
.
texture
,
{
this
.
life
:
1.5
,
this
.
lifeVar
:
1.0
,
this
.
posVar
:
Point
.
origin
,
this
.
startSize
:
2.5
,
this
.
startSizeVar
:
0.5
,
this
.
endSize
:
0.0
,
this
.
endSizeVar
:
0.0
,
this
.
startRotation
:
0.0
,
this
.
startRotationVar
:
0.0
,
this
.
endRotation
:
0.0
,
this
.
endRotationVar
:
0.0
,
this
.
rotateToMovement
:
false
,
this
.
direction
:
0.0
,
this
.
directionVar
:
360.0
,
this
.
speed
:
100.0
,
this
.
speedVar
:
50.0
,
this
.
radialAcceleration
:
0.0
,
this
.
radialAccelerationVar
:
0.0
,
this
.
tangentialAcceleration
:
0.0
,
this
.
tangentialAccelerationVar
:
0.0
,
this
.
gravity
,
this
.
maxParticles
:
100
,
this
.
emissionRate
:
50.0
,
this
.
colorSequence
,
this
.
alphaVar
:
0
,
this
.
redVar
:
0
,
this
.
greenVar
:
0
,
this
.
blueVar
:
0
,
this
.
transferMode
:
TransferMode
.
plus
,
this
.
numParticlesToEmit
:
0
,
this
.
autoRemoveOnFinish
:
true
})
{
_particles
=
new
List
<
_Particle
>();
_emitCounter
=
0.0
;
// _elapsedTime = 0.0;
if
(
gravity
==
null
)
gravity
=
new
Vector2
.
zero
();
if
(
colorSequence
==
null
)
colorSequence
=
new
ColorSequence
.
fromStartAndEndColor
(
new
Color
(
0xffffffff
),
new
Color
(
0x00ffffff
));
}
@override
void
update
(
double
dt
)
{
// TODO: Fix this (it's a temp fix for low framerates)
...
...
@@ -249,11 +267,11 @@ class ParticleSystem extends Node {
tangential
.
scale
(
particle
.
accelerations
.
tangentialAccel
);
// (gravity + radial + tangential) * dt
Vector2
accel
=
(
gravity
+
radial
+
tangential
).
scale
(
dt
);
final
Vector2
accel
=
(
_
gravity
+
radial
+
tangential
).
scale
(
dt
);
particle
.
dir
+=
accel
;
}
else
if
(
gravity
[
0
]
!=
0.0
||
gravity
[
1
]
!=
0
)
{
}
else
if
(
_gravity
[
0
]
!=
0.0
||
_
gravity
[
1
]
!=
0
)
{
// gravity
Vector2
accel
=
new
Vector2
.
copy
(
gravity
).
scale
(
dt
);
final
Vector2
accel
=
new
Vector2
.
copy
(
_
gravity
).
scale
(
dt
);
particle
.
dir
+=
accel
;
}
...
...
@@ -362,7 +380,8 @@ class ParticleSystem extends Node {
@override
void
paint
(
Canvas
canvas
)
{
if
(
opacity
==
0.0
)
return
;
if
(
opacity
==
0.0
)
return
;
List
<
RSTransform
>
transforms
=
<
RSTransform
>[];
List
<
Rect
>
rects
=
<
Rect
>[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment