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
01ac0095
Commit
01ac0095
authored
Jul 28, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates startled in game demo to use drawAtlas
parent
0d7156fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
26 deletions
+20
-26
game_demo_world.dart
packages/flutter/example/game/lib/game_demo_world.dart
+20
-26
No files found.
packages/flutter/example/game/lib/game_demo_world.dart
View file @
01ac0095
...
...
@@ -562,49 +562,43 @@ class Laser extends Sprite {
// Background starfield
class
StarField
extends
Node
{
Image
_image
;
int
_numStars
;
List
<
Point
>
_starPositions
;
List
<
double
>
_starScales
;
List
<
double
>
_opacity
;
List
<
Texture
>
_textures
;
List
<
Rect
>
_rects
;
List
<
Color
>
_colors
;
Paint
_paint
=
new
Paint
()
..
setFilterQuality
(
sky
.
FilterQuality
.
low
)
..
isAntiAlias
=
false
..
setTransferMode
(
sky
.
TransferMode
.
plus
);
StarField
(
SpriteSheet
spriteSheet
,
this
.
_numStars
)
{
_starPositions
=
[];
_starScales
=
[];
_
opacity
=
[];
_
texture
s
=
[];
_
colors
=
[];
_
rect
s
=
[];
for
(
int
i
=
0
;
i
<
_numStars
;
i
++)
{
_starPositions
.
add
(
new
Point
(
_rand
.
nextDouble
()
*
_gameSizeWidth
,
_rand
.
nextDouble
()
*
_gameSizeHeight
));
_starScales
.
add
(
_rand
.
nextDouble
());
_
opacity
.
add
(
_rand
.
nextDouble
()
*
0.5
+
0.5
);
_
textures
.
add
(
spriteSheet
[
"star_
${_rand.nextInt(2)}
.png"
]
);
_
colors
.
add
(
new
Color
.
fromARGB
((
255.0
*
(
_rand
.
nextDouble
()
*
0.5
+
0.5
)).
toInt
(),
255
,
255
,
255
)
);
_
rects
.
add
(
spriteSheet
[
"star_
${_rand.nextInt(2)}
.png"
].
frame
);
}
_image
=
spriteSheet
.
image
;
}
void
paint
(
PaintingCanvas
canvas
)
{
// Setup paint object for opacity and transfer mode
Paint
paint
=
new
Paint
();
paint
.
setTransferMode
(
sky
.
TransferMode
.
plus
);
double
baseScaleX
=
64.0
/
_textures
[
0
].
size
.
width
;
double
baseScaleY
=
64.0
/
_textures
[
0
].
size
.
height
;
// Draw each star
// Create a transform for each star
List
<
sky
.
RSTransform
>
transforms
=
[];
for
(
int
i
=
0
;
i
<
_numStars
;
i
++)
{
Point
pos
=
_starPositions
[
i
];
double
scale
=
_starScales
[
i
];
paint
.
color
=
new
Color
.
fromARGB
((
255.0
*
_opacity
[
i
]).
toInt
(),
255
,
255
,
255
);
canvas
.
save
();
canvas
.
translate
(
pos
.
x
,
pos
.
y
);
canvas
.
scale
(
baseScaleX
*
scale
,
baseScaleY
*
scale
);
canvas
.
drawImageRect
(
_textures
[
i
].
image
,
_textures
[
i
].
frame
,
_textures
[
i
].
spriteSourceSize
,
paint
);
canvas
.
restore
();
sky
.
RSTransform
transform
=
new
sky
.
RSTransform
(
_starScales
[
i
],
0.0
,
_starPositions
[
i
].
x
,
_starPositions
[
i
].
y
);
transforms
.
add
(
transform
);
}
// Draw the stars
canvas
.
drawAtlas
(
_image
,
transforms
,
_rects
,
_colors
,
sky
.
TransferMode
.
modulate
,
null
,
_paint
);
}
void
move
(
double
dx
,
double
dy
)
{
...
...
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