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
e0454520
Commit
e0454520
authored
Aug 04, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimizes texture drawing by removing a canvas.translate call
parent
4ff5339a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
texture.dart
packages/flutter/example/game/lib/texture.dart
+14
-12
No files found.
packages/flutter/example/game/lib/texture.dart
View file @
e0454520
...
...
@@ -74,17 +74,18 @@ class Texture {
}
void
drawTexture
(
PaintingCanvas
canvas
,
Point
position
,
Paint
paint
)
{
// Account for position
// Get drawing position
double
x
=
position
.
x
;
double
y
=
position
.
y
;
// Draw the texture
if
(
rotated
)
{
// Account for position
bool
translate
=
(
x
!=
0
||
y
!=
0
);
if
(
translate
)
{
canvas
.
translate
(
x
,
y
);
}
// Draw the texture
if
(
rotated
)
{
// Calculate the rotated frame and spriteSourceSize
Size
originalFrameSize
=
frame
.
size
;
Rect
rotatedFrame
=
frame
.
topLeft
&
new
Size
(
originalFrameSize
.
height
,
originalFrameSize
.
width
);
...
...
@@ -97,14 +98,15 @@ class Texture {
canvas
.
rotate
(-
math
.
PI
/
2.0
);
canvas
.
drawImageRect
(
image
,
rotatedFrame
,
rotatedSpriteSourceSize
,
paint
);
canvas
.
rotate
(
math
.
PI
/
2.0
);
}
else
{
// Draw the sprite
canvas
.
drawImageRect
(
image
,
frame
,
spriteSourceSize
,
paint
);
}
// Translate back
if
(
translate
)
{
canvas
.
translate
(-
x
,
-
y
);
}
}
else
{
// Draw the sprite
Rect
dstRect
=
new
Rect
.
fromLTWH
(
x
+
spriteSourceSize
.
left
,
y
+
spriteSourceSize
.
top
,
spriteSourceSize
.
width
,
spriteSourceSize
.
height
);
canvas
.
drawImageRect
(
image
,
frame
,
dstRect
,
paint
);
}
}
}
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