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
ab104c80
Commit
ab104c80
authored
Oct 05, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle removal of sprite physics bodies during the physics simulation
parent
071201a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
1 deletion
+22
-1
test_physics.dart
examples/game/test_physics.dart
+1
-0
physics_body.dart
packages/flutter_sprites/lib/physics_body.dart
+1
-1
physics_node.dart
packages/flutter_sprites/lib/physics_node.dart
+20
-0
No files found.
examples/game/test_physics.dart
View file @
ab104c80
...
...
@@ -83,6 +83,7 @@ class TestBed extends NodeWithSize {
void
myCallback
(
PhysicsContactType
type
,
PhysicsContact
contact
)
{
print
(
"CONTACT type:
$type
"
);
contact
.
nodeB
.
removeFromParent
();
}
bool
handleEvent
(
SpriteBoxEvent
event
)
{
...
...
packages/flutter_sprites/lib/physics_body.dart
View file @
ab104c80
...
...
@@ -120,7 +120,7 @@ class PhysicsBody {
void
_detach
()
{
if
(
_attached
)
{
_physicsNode
.
b2World
.
destroyBody
(
_body
);
_physicsNode
.
_bodiesScheduledForDestruction
.
add
(
_body
);
_attached
=
false
;
}
}
...
...
packages/flutter_sprites/lib/physics_node.dart
View file @
ab104c80
...
...
@@ -31,6 +31,8 @@ class PhysicsNode extends Node {
_ContactHandler
_contactHandler
;
List
<
box2d
.
Body
>
_bodiesScheduledForDestruction
=
[];
double
b2WorldToNodeConversionFactor
=
500.0
;
Offset
get
gravity
{
...
...
@@ -57,6 +59,9 @@ class PhysicsNode extends Node {
}
void
_stepPhysics
(
double
dt
)
{
// Remove bodies that were marked for destruction during the update phase
_removeBodiesScheduledForDestruction
();
// Calculate a step in the simulation
b2World
.
stepDt
(
dt
,
10
,
10
);
...
...
@@ -71,6 +76,16 @@ class PhysicsNode extends Node {
body
.
_node
.
_setRotationFromPhysics
(
degrees
(
b2Body
.
getAngle
()));
}
// Remove bodies that were marked for destruction during the simulation
_removeBodiesScheduledForDestruction
();
}
void
_removeBodiesScheduledForDestruction
()
{
for
(
box2d
.
Body
b2Body
in
_bodiesScheduledForDestruction
)
{
b2World
.
destroyBody
(
b2Body
);
}
_bodiesScheduledForDestruction
.
clear
();
}
void
_updatePosition
(
PhysicsBody
body
,
Point
position
)
{
...
...
@@ -257,6 +272,11 @@ class _ContactHandler extends box2d.ContactListener {
b2Contact
.
isTouching
(),
b2Contact
.
isEnabled
()
);
if
(
type
==
PhysicsContactType
.
postSolve
)
{
}
// Make callback
info
.
callback
(
type
,
contact
);
...
...
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