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
dd956b9f
Commit
dd956b9f
authored
Oct 16, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1645 from vlidholt/master
Adds teleporting methods for moving sprite kinematic bodies
parents
2609f7bf
23bae330
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
node.dart
packages/flutter_sprites/lib/src/node.dart
+27
-0
physics_node.dart
packages/flutter_sprites/lib/src/physics_node.dart
+7
-0
No files found.
packages/flutter_sprites/lib/src/node.dart
View file @
dd956b9f
...
...
@@ -148,6 +148,16 @@ class Node {
invalidateTransformMatrix
();
}
void
teleportRotation
(
double
rotation
)
{
assert
(
rotation
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
PhysicsNode
)
{
_physicsBody
.
_body
.
setTransform
(
_physicsBody
.
_body
.
position
,
radians
(
rotation
));
_physicsBody
.
_body
.
angularVelocity
=
0.0
;
_physicsBody
.
_body
.
setType
(
box2d
.
BodyType
.
STATIC
);
}
_setRotationFromPhysics
(
rotation
);
}
/// The position of this node relative to its parent.
///
/// myNode.position = new Point(42.0, 42.0);
...
...
@@ -172,6 +182,23 @@ class Node {
invalidateTransformMatrix
();
}
void
teleportPosition
(
Point
position
)
{
assert
(
position
!=
null
);
if
(
_physicsBody
!=
null
&&
parent
is
PhysicsNode
)
{
PhysicsNode
physicsNode
=
parent
;
_physicsBody
.
_body
.
setTransform
(
new
Vector2
(
position
.
x
/
physicsNode
.
b2WorldToNodeConversionFactor
,
position
.
y
/
physicsNode
.
b2WorldToNodeConversionFactor
),
_physicsBody
.
_body
.
getAngle
()
);
_physicsBody
.
_body
.
linearVelocity
=
new
Vector2
.
zero
();
_physicsBody
.
_body
.
setType
(
box2d
.
BodyType
.
STATIC
);
}
_setPositionFromPhysics
(
position
);
}
/// The skew along the x-axis of this node in degrees.
///
/// myNode.skewX = 45.0;
...
...
packages/flutter_sprites/lib/src/physics_node.dart
View file @
dd956b9f
...
...
@@ -112,6 +112,13 @@ class PhysicsNode extends Node {
for
(
box2d
.
Body
b2Body
=
b2World
.
bodyList
;
b2Body
!=
null
;
b2Body
=
b2Body
.
getNext
())
{
// Update visual position and rotation
PhysicsBody
body
=
b2Body
.
userData
;
if
(
b2Body
.
getType
()
==
box2d
.
BodyType
.
KINEMATIC
)
{
body
.
_targetPosition
=
null
;
body
.
_targetAngle
=
null
;
}
// Update visual position and rotation
body
.
_node
.
_setPositionFromPhysics
(
new
Point
(
b2Body
.
position
.
x
*
b2WorldToNodeConversionFactor
,
b2Body
.
position
.
y
*
b2WorldToNodeConversionFactor
...
...
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