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
ebaa45c7
Commit
ebaa45c7
authored
Oct 06, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1508 from vlidholt/master
Improvements to sprite physics
parents
2d0d1645
b6e12ca9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
22 deletions
+136
-22
physics_body.dart
packages/flutter_sprites/lib/physics_body.dart
+136
-22
No files found.
packages/flutter_sprites/lib/physics_body.dart
View file @
ebaa45c7
...
...
@@ -13,26 +13,36 @@ class PhysicsBody {
double
friction:
0.0
,
double
restitution:
0.0
,
bool
isSensor:
false
,
this
.
linearVelocity
:
Offset
.
zero
,
this
.
angularVelocity
:
0.0
,
Offset
linearVelocity:
Offset
.
zero
,
double
angularVelocity:
0.0
,
this
.
linearDampening
:
0.0
,
this
.
angularDampening
:
0.0
,
this
.
allowSleep
:
true
,
this
.
awake
:
true
,
this
.
fixedRotation
:
false
,
this
.
bullet
:
false
,
this
.
active
:
true
,
double
awake
angularDampening:
0.0
,
bool
allowSleep:
true
,
bool
awake:
true
,
bool
fixedRotation:
false
,
bool
bullet:
false
,
bool
active:
true
,
this
.
gravityScale
:
1.0
})
{
this
.
density
=
density
;
this
.
friction
=
friction
;
this
.
restitution
=
restitution
;
this
.
isSensor
=
isSensor
;
this
.
linearVelocity
=
linearVelocity
;
this
.
angularVelocity
=
angularVelocity
;
this
.
angularDampening
=
angularDampening
;
this
.
allowSleep
=
allowSleep
;
this
.
awake
=
awake
;
this
.
fixedRotation
=
fixedRotation
;
this
.
bullet
=
bullet
;
this
.
active
=
active
;
}
Object
tag
;
PhysicsShape
shape
;
final
PhysicsShape
shape
;
PhysicsBodyType
type
;
...
...
@@ -45,7 +55,7 @@ class PhysicsBody {
if
(
_body
==
null
)
return
;
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
f
.
setDensity
(
density
);
}
}
...
...
@@ -59,7 +69,7 @@ class PhysicsBody {
if
(
_body
==
null
)
return
;
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
f
.
setFriction
(
friction
);
}
}
...
...
@@ -73,7 +83,7 @@ class PhysicsBody {
if
(
_body
==
null
)
return
;
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
f
.
setRestitution
(
restitution
);
}
}
...
...
@@ -87,27 +97,131 @@ class PhysicsBody {
if
(
_body
==
null
)
return
;
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
for
(
box2d
.
Fixture
f
=
_body
.
getFixtureList
();
f
!=
null
;
f
=
f
.
getNext
())
{
f
.
setSensor
(
isSensor
);
}
}
Offset
linearVelocity
;
double
angularVelocity
;
Offset
_linearVelocity
;
Offset
get
linearVelocity
{
if
(
_body
==
null
)
return
_linearVelocity
;
else
{
double
dx
=
_body
.
linearVelocity
.
x
*
_physicsNode
.
b2WorldToNodeConversionFactor
;
double
dy
=
_body
.
linearVelocity
.
y
*
_physicsNode
.
b2WorldToNodeConversionFactor
;
return
new
Offset
(
dx
,
dy
);
}
}
set
linearVelocity
(
Offset
linearVelocity
)
{
_linearVelocity
=
linearVelocity
;
if
(
_body
!=
null
)
{
Vector2
vec
=
new
Vector2
(
linearVelocity
.
dx
/
_physicsNode
.
b2WorldToNodeConversionFactor
,
linearVelocity
.
dy
/
_physicsNode
.
b2WorldToNodeConversionFactor
);
_body
.
linearVelocity
=
vec
;
}
}
double
_angularVelocity
;
double
get
angularVelocity
{
if
(
_body
==
null
)
return
_angularVelocity
;
else
return
_body
.
angularVelocity
;
}
set
angularVelocity
(
double
angularVelocity
)
{
_angularVelocity
=
angularVelocity
;
if
(
_body
!=
null
)
{
_body
.
angularVelocity
=
angularVelocity
;
}
}
// TODO: Should this be editable in box2d.Body ?
final
double
linearDampening
;
double
_angularDampening
;
double
get
angularDampening
=>
_angularDampening
;
set
angularDampening
(
double
angularDampening
)
{
_angularDampening
=
angularDampening
;
if
(
_body
!=
null
)
_body
.
angularDamping
=
angularDampening
;
}
bool
_allowSleep
;
bool
get
allowSleep
=>
_allowSleep
;
set
allowSleep
(
bool
allowSleep
)
{
_allowSleep
=
allowSleep
;
if
(
_body
!=
null
)
_body
.
setSleepingAllowed
(
allowSleep
);
}
bool
_awake
;
bool
get
awake
{
if
(
_body
!=
null
)
return
_body
.
isAwake
();
else
return
_awake
;
}
set
awake
(
bool
awake
)
{
_awake
=
awake
;
if
(
_body
!=
null
)
_body
.
setAwake
(
awake
);
}
bool
_fixedRotation
;
bool
get
fixedRotation
=>
_fixedRotation
;
set
fixedRotation
(
bool
fixedRotation
)
{
_fixedRotation
=
fixedRotation
;
if
(
_body
!=
null
)
_body
.
setFixedRotation
(
fixedRotation
);
}
bool
_bullet
;
double
linearDampening
;
bool
get
bullet
=>
_bullet
;
double
angularDampening
;
set
bullet
(
bool
bullet
)
{
_bullet
=
bullet
;
bool
allowSleep
;
if
(
_body
!=
null
)
{
_body
.
setBullet
(
bullet
);
}
}
bool
awak
e
;
bool
_activ
e
;
bool
fixedRotation
;
bool
get
active
{
if
(
_body
!=
null
)
return
_body
.
isActive
();
else
return
_active
;
}
bool
bullet
;
set
active
(
bool
active
)
{
_active
=
active
;
bool
active
;
if
(
_body
!=
null
)
_body
.
setActive
(
active
);
}
double
gravityScale
;
...
...
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