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
0a02ea45
Commit
0a02ea45
authored
Aug 10, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #521 from vlidholt/master
Adds new Layer class to sprites
parents
03403d08
35bdbbfe
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
37 deletions
+66
-37
game_demo_world.dart
examples/game/lib/game_demo_world.dart
+1
-1
layer.dart
examples/game/lib/layer.dart
+19
-0
node_with_size.dart
examples/game/lib/node_with_size.dart
+2
-2
sprite.dart
examples/game/lib/sprite.dart
+43
-34
sprites.dart
examples/game/lib/sprites.dart
+1
-0
No files found.
examples/game/lib/game_demo_world.dart
View file @
0a02ea45
...
@@ -650,7 +650,7 @@ class Hud extends NodeWithSize {
...
@@ -650,7 +650,7 @@ class Hud extends NodeWithSize {
_dirtyScore
=
true
;
_dirtyScore
=
true
;
}
}
Hud
(
this
.
spriteSheetUI
)
{
Hud
(
this
.
spriteSheetUI
)
:
super
(
Size
.
zero
)
{
pivot
=
Point
.
origin
;
pivot
=
Point
.
origin
;
sprtBgScore
=
new
Sprite
(
spriteSheetUI
[
"scoreboard.png"
]);
sprtBgScore
=
new
Sprite
(
spriteSheetUI
[
"scoreboard.png"
]);
...
...
examples/game/lib/layer.dart
0 → 100644
View file @
0a02ea45
part of
sprites
;
class
Layer
extends
Node
with
SpritePaint
{
Paint
_cachedPaint
=
new
Paint
()
..
setFilterQuality
(
FilterQuality
.
low
)
..
isAntiAlias
=
false
;
void
_prePaint
(
PaintingCanvas
canvas
,
Matrix4
matrix
)
{
super
.
_prePaint
(
canvas
,
matrix
);
_updatePaint
(
_cachedPaint
);
canvas
.
saveLayer
(
null
,
_cachedPaint
);
}
void
_postPaint
(
PaintingCanvas
canvas
,
Matrix4
totalMatrix
)
{
canvas
.
restore
();
super
.
_postPaint
(
canvas
,
totalMatrix
);
}
}
examples/game/lib/node_with_size.dart
View file @
0a02ea45
...
@@ -21,9 +21,9 @@ class NodeWithSize extends Node {
...
@@ -21,9 +21,9 @@ class NodeWithSize extends Node {
/// The default [size] is zero and the default [pivot] point is the origin. Subclasses may change the default values.
/// The default [size] is zero and the default [pivot] point is the origin. Subclasses may change the default values.
///
///
/// var myNodeWithSize = new NodeWithSize(new Size(1024.0, 1024.0));
/// var myNodeWithSize = new NodeWithSize(new Size(1024.0, 1024.0));
NodeWithSize
(
[
Size
this
.
size
,
Point
this
.
pivot
]
)
{
NodeWithSize
(
Size
this
.
size
)
{
if
(
size
==
null
)
size
=
Size
.
zero
;
if
(
size
==
null
)
size
=
Size
.
zero
;
if
(
pivot
==
null
)
pivot
=
Point
.
origin
;
pivot
=
Point
.
origin
;
}
}
/// Call this method in your [paint] method if you want the origin of your drawing to be the top left corner of the
/// Call this method in your [paint] method if you want the origin of your drawing to be the top left corner of the
...
...
examples/game/lib/sprite.dart
View file @
0a02ea45
part of
sprites
;
part of
sprites
;
/// A Sprite is a [Node] that renders a bitmap image to the screen.
/// A Sprite is a [Node] that renders a bitmap image to the screen.
class
Sprite
extends
NodeWithSize
{
class
Sprite
extends
NodeWithSize
with
SpritePaint
{
/// The texture that the sprite will render to screen.
/// The texture that the sprite will render to screen.
///
///
...
@@ -15,19 +15,6 @@ class Sprite extends NodeWithSize {
...
@@ -15,19 +15,6 @@ class Sprite extends NodeWithSize {
///
///
/// mySprite.constrainProportions = true;
/// mySprite.constrainProportions = true;
bool
constrainProportions
=
false
;
bool
constrainProportions
=
false
;
double
_opacity
=
1.0
;
/// The color to draw on top of the sprite, null if no color overlay is used.
///
/// // Color the sprite red
/// mySprite.colorOverlay = new Color(0x77ff0000);
Color
colorOverlay
;
/// The transfer mode used when drawing the sprite to screen.
///
/// // Add the colors of the sprite with the colors of the background
/// mySprite.transferMode = TransferMode.plusMode;
TransferMode
transferMode
;
Paint
_cachedPaint
=
new
Paint
()
Paint
_cachedPaint
=
new
Paint
()
..
setFilterQuality
(
FilterQuality
.
low
)
..
setFilterQuality
(
FilterQuality
.
low
)
...
@@ -36,7 +23,7 @@ class Sprite extends NodeWithSize {
...
@@ -36,7 +23,7 @@ class Sprite extends NodeWithSize {
/// Creates a new sprite from the provided [texture].
/// Creates a new sprite from the provided [texture].
///
///
/// var mySprite = new Sprite(myTexture)
/// var mySprite = new Sprite(myTexture)
Sprite
([
this
.
texture
])
{
Sprite
([
this
.
texture
])
:
super
(
Size
.
zero
)
{
if
(
texture
!=
null
)
{
if
(
texture
!=
null
)
{
size
=
texture
.
size
;
size
=
texture
.
size
;
pivot
=
texture
.
pivot
;
pivot
=
texture
.
pivot
;
...
@@ -48,7 +35,7 @@ class Sprite extends NodeWithSize {
...
@@ -48,7 +35,7 @@ class Sprite extends NodeWithSize {
/// Creates a new sprite from the provided [image].
/// Creates a new sprite from the provided [image].
///
///
/// var mySprite = new Sprite.fromImage(myImage);
/// var mySprite = new Sprite.fromImage(myImage);
Sprite
.
fromImage
(
Image
image
)
{
Sprite
.
fromImage
(
Image
image
)
:
super
(
Size
.
zero
)
{
assert
(
image
!=
null
);
assert
(
image
!=
null
);
texture
=
new
Texture
(
image
);
texture
=
new
Texture
(
image
);
...
@@ -57,17 +44,6 @@ class Sprite extends NodeWithSize {
...
@@ -57,17 +44,6 @@ class Sprite extends NodeWithSize {
pivot
=
new
Point
(
0.5
,
0.5
);
pivot
=
new
Point
(
0.5
,
0.5
);
}
}
/// The opacity of the sprite in the range 0.0 to 1.0.
///
/// mySprite.opacity = 0.5;
double
get
opacity
=>
_opacity
;
void
set
opacity
(
double
opacity
)
{
assert
(
opacity
!=
null
);
assert
(
opacity
>=
0.0
&&
opacity
<=
1.0
);
_opacity
=
opacity
;
}
void
paint
(
PaintingCanvas
canvas
)
{
void
paint
(
PaintingCanvas
canvas
)
{
// Account for pivot point
// Account for pivot point
applyTransformForPivot
(
canvas
);
applyTransformForPivot
(
canvas
);
...
@@ -95,13 +71,7 @@ class Sprite extends NodeWithSize {
...
@@ -95,13 +71,7 @@ class Sprite extends NodeWithSize {
canvas
.
scale
(
scaleX
,
scaleY
);
canvas
.
scale
(
scaleX
,
scaleY
);
// Setup paint object for opacity and transfer mode
// Setup paint object for opacity and transfer mode
_cachedPaint
.
color
=
new
Color
.
fromARGB
((
255.0
*
_opacity
).
toInt
(),
255
,
255
,
255
);
_updatePaint
(
_cachedPaint
);
if
(
colorOverlay
!=
null
)
{
_cachedPaint
.
setColorFilter
(
new
ColorFilter
.
mode
(
colorOverlay
,
TransferMode
.
srcATop
));
}
if
(
transferMode
!=
null
)
{
_cachedPaint
.
setTransferMode
(
transferMode
);
}
// Do actual drawing of the sprite
// Do actual drawing of the sprite
texture
.
drawTexture
(
canvas
,
Point
.
origin
,
_cachedPaint
);
texture
.
drawTexture
(
canvas
,
Point
.
origin
,
_cachedPaint
);
...
@@ -112,3 +82,42 @@ class Sprite extends NodeWithSize {
...
@@ -112,3 +82,42 @@ class Sprite extends NodeWithSize {
}
}
}
}
}
}
abstract
class
SpritePaint
{
double
_opacity
=
1.0
;
/// The opacity of the sprite in the range 0.0 to 1.0.
///
/// mySprite.opacity = 0.5;
double
get
opacity
=>
_opacity
;
void
set
opacity
(
double
opacity
)
{
assert
(
opacity
!=
null
);
assert
(
opacity
>=
0.0
&&
opacity
<=
1.0
);
_opacity
=
opacity
;
}
/// The color to draw on top of the sprite, null if no color overlay is used.
///
/// // Color the sprite red
/// mySprite.colorOverlay = new Color(0x77ff0000);
Color
colorOverlay
;
/// The transfer mode used when drawing the sprite to screen.
///
/// // Add the colors of the sprite with the colors of the background
/// mySprite.transferMode = TransferMode.plusMode;
TransferMode
transferMode
;
void
_updatePaint
(
Paint
paint
)
{
paint
.
color
=
new
Color
.
fromARGB
((
255.0
*
_opacity
).
toInt
(),
255
,
255
,
255
);
if
(
colorOverlay
!=
null
)
{
_cachedPaint
.
setColorFilter
(
new
ColorFilter
.
mode
(
colorOverlay
,
TransferMode
.
srcATop
));
}
if
(
transferMode
!=
null
)
{
_cachedPaint
.
setTransferMode
(
transferMode
);
}
}
}
examples/game/lib/sprites.dart
View file @
0a02ea45
...
@@ -21,6 +21,7 @@ import 'package:vector_math/vector_math.dart';
...
@@ -21,6 +21,7 @@ import 'package:vector_math/vector_math.dart';
part
'action.dart'
;
part
'action.dart'
;
part
'color_secuence.dart'
;
part
'color_secuence.dart'
;
part
'image_map.dart'
;
part
'image_map.dart'
;
part
'layer.dart'
;
part
'node.dart'
;
part
'node.dart'
;
part
'node3d.dart'
;
part
'node3d.dart'
;
part
'node_with_size.dart'
;
part
'node_with_size.dart'
;
...
...
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