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
88afaefb
Commit
88afaefb
authored
Jul 21, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates sprite widget to handle changes to renderbox
parent
41695fb1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
10 deletions
+49
-10
sprite_box.dart
packages/flutter/example/game/lib/sprite_box.dart
+46
-6
sprite_widget.dart
packages/flutter/example/game/lib/sprite_widget.dart
+3
-4
No files found.
packages/flutter/example/game/lib/sprite_box.dart
View file @
88afaefb
...
@@ -28,6 +28,20 @@ class SpriteBox extends RenderBox {
...
@@ -28,6 +28,20 @@ class SpriteBox extends RenderBox {
// Root node for drawing
// Root node for drawing
NodeWithSize
_rootNode
;
NodeWithSize
_rootNode
;
void
set
rootNode
(
NodeWithSize
value
)
{
if
(
value
==
_rootNode
)
return
;
// Remove sprite box references
if
(
_rootNode
!=
null
)
_removeSpriteBoxReference
(
_rootNode
);
// Update the value
_rootNode
=
value
;
// Add new references
_addSpriteBoxReference
(
_rootNode
);
}
// Tracking of frame rate and updates
// Tracking of frame rate and updates
double
_lastTimeStamp
;
double
_lastTimeStamp
;
int
_numFrames
=
0
;
int
_numFrames
=
0
;
...
@@ -36,6 +50,15 @@ class SpriteBox extends RenderBox {
...
@@ -36,6 +50,15 @@ class SpriteBox extends RenderBox {
// Transformation mode
// Transformation mode
SpriteBoxTransformMode
_transformMode
;
SpriteBoxTransformMode
_transformMode
;
void
set
transformMode
(
SpriteBoxTransformMode
value
)
{
if
(
value
==
_transformMode
)
return
;
_transformMode
=
value
;
// Invalidate stuff
if
(
attached
)
performLayout
();
}
/// The transform mode used by the [SpriteBox].
/// The transform mode used by the [SpriteBox].
SpriteBoxTransformMode
get
transformMode
=>
_transformMode
;
SpriteBoxTransformMode
get
transformMode
=>
_transformMode
;
...
@@ -44,6 +67,10 @@ class SpriteBox extends RenderBox {
...
@@ -44,6 +67,10 @@ class SpriteBox extends RenderBox {
List
<
Node
>
_eventTargets
;
List
<
Node
>
_eventTargets
;
Rect
_visibleArea
;
Rect
get
visibleArea
=>
_visibleArea
;
// Setup
// Setup
/// Creates a new SpriteBox with a node as its content, by default uses letterboxing.
/// Creates a new SpriteBox with a node as its content, by default uses letterboxing.
...
@@ -58,15 +85,17 @@ class SpriteBox extends RenderBox {
...
@@ -58,15 +85,17 @@ class SpriteBox extends RenderBox {
assert
(
rootNode
.
_spriteBox
==
null
);
assert
(
rootNode
.
_spriteBox
==
null
);
// Setup root node
// Setup root node
_rootNode
=
rootNode
;
this
.
rootNode
=
rootNode
;
// Assign SpriteBox reference to all the nodes
_addSpriteBoxReference
(
_rootNode
);
// Setup transform mode
// Setup transform mode
_transformMode
=
mode
;
this
.
transformMode
=
mode
;
}
_scheduleTick
();
void
_removeSpriteBoxReference
(
Node
node
)
{
node
.
_spriteBox
=
null
;
for
(
Node
child
in
node
.
_children
)
{
_removeSpriteBoxReference
(
child
);
}
}
}
void
_addSpriteBoxReference
(
Node
node
)
{
void
_addSpriteBoxReference
(
Node
node
)
{
...
@@ -76,6 +105,16 @@ class SpriteBox extends RenderBox {
...
@@ -76,6 +105,16 @@ class SpriteBox extends RenderBox {
}
}
}
}
void
attach
()
{
super
.
attach
();
_scheduleTick
();
}
void
detach
()
{
super
.
detach
();
}
// Properties
// Properties
/// The root node of the node tree that is rendered by this box.
/// The root node of the node tree that is rendered by this box.
...
@@ -271,6 +310,7 @@ class SpriteBox extends RenderBox {
...
@@ -271,6 +310,7 @@ class SpriteBox extends RenderBox {
}
}
void
_tick
(
double
timeStamp
)
{
void
_tick
(
double
timeStamp
)
{
if
(!
attached
)
return
;
// Calculate the time between frames in seconds
// Calculate the time between frames in seconds
if
(
_lastTimeStamp
==
null
)
_lastTimeStamp
=
timeStamp
;
if
(
_lastTimeStamp
==
null
)
_lastTimeStamp
=
timeStamp
;
...
...
packages/flutter/example/game/lib/sprite_widget.dart
View file @
88afaefb
...
@@ -31,8 +31,7 @@ class SpriteWidget extends OneChildRenderObjectWrapper {
...
@@ -31,8 +31,7 @@ class SpriteWidget extends OneChildRenderObjectWrapper {
void
syncRenderObject
(
SpriteWidget
old
)
{
void
syncRenderObject
(
SpriteWidget
old
)
{
super
.
syncRenderObject
(
old
);
super
.
syncRenderObject
(
old
);
// SpriteBox doesn't allow mutation of these properties
root
.
rootNode
=
rootNode
;
assert
(
rootNode
==
root
.
rootNode
);
root
.
transformMode
=
transformMode
;
assert
(
transformMode
==
root
.
_transformMode
);
}
}
}
}
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