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
333c8f5f
Commit
333c8f5f
authored
Oct 08, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates sprite physics test
parent
95a0acea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
test_physics.dart
examples/game/test_physics.dart
+31
-20
No files found.
examples/game/test_physics.dart
View file @
333c8f5f
...
...
@@ -45,24 +45,11 @@ main() async {
}
class
TestBed
extends
NodeWithSize
{
Sprite
_ship
;
Sprite
_obstacle
;
PhysicsNode
_physicsNode
;
TestBed
()
:
super
(
new
Size
(
1024.0
,
1024.0
))
{
PhysicsNode
physicsNode
=
new
PhysicsNode
(
new
Offset
(
0.0
,
100.0
));
_ship
=
new
Sprite
(
_spriteSheet
[
"ship.png"
]);
_ship
.
position
=
new
Point
(
512.0
,
512.0
);
_ship
.
size
=
new
Size
(
64.0
,
64.0
);
_ship
.
physicsBody
=
new
PhysicsBody
(
new
PhysicsShapeGroup
([
new
PhysicsShapeCircle
(
Point
.
origin
,
32.0
),
new
PhysicsShapePolygon
([
new
Point
(
0.0
,
0.0
),
new
Point
(
50.0
,
0.0
),
new
Point
(
50.0
,
50.0
),
new
Point
(
0.0
,
50.0
)])
]),
friction:
0.5
,
tag:
"ship"
);
physicsNode
.
addChild
(
_ship
);
_physicsNode
=
new
PhysicsNode
(
new
Offset
(
0.0
,
100.0
));
_obstacle
=
new
Sprite
(
_spriteSheet
[
"ship.png"
]);
_obstacle
.
position
=
new
Point
(
532.0
,
800.0
);
...
...
@@ -73,23 +60,47 @@ class TestBed extends NodeWithSize {
friction:
0.5
,
tag:
"obstacle"
);
physicsNode
.
addChild
(
_obstacle
);
physicsNode
.
addContactCallback
(
myCallback
,
"obstacle"
,
"ship"
,
PhysicsContactType
.
begin
);
_
physicsNode
.
addChild
(
_obstacle
);
_
physicsNode
.
addContactCallback
(
myCallback
,
"obstacle"
,
"ship"
,
PhysicsContactType
.
begin
);
addChild
(
physicsNode
);
addChild
(
_
physicsNode
);
userInteractionEnabled
=
true
;
}
void
myCallback
(
PhysicsContactType
type
,
PhysicsContact
contact
)
{
print
(
"CONTACT type:
$type
"
);
contact
.
nodeB
.
removeFromParent
();
}
bool
handleEvent
(
SpriteBoxEvent
event
)
{
if
(
event
.
type
==
"pointerdown"
)
{
Point
pos
=
convertPointToNodeSpace
(
event
.
boxPosition
);
_ship
.
position
=
pos
;
Sprite
shipA
;
shipA
=
new
Sprite
(
_spriteSheet
[
"ship.png"
]);
shipA
.
position
=
new
Point
(
pos
.
x
-
40.0
,
pos
.
y
);
shipA
.
size
=
new
Size
(
64.0
,
64.0
);
shipA
.
physicsBody
=
new
PhysicsBody
(
new
PhysicsShapeCircle
(
Point
.
origin
,
32.0
),
friction:
0.5
,
tag:
"ship"
);
_physicsNode
.
addChild
(
shipA
);
shipA
.
physicsBody
.
applyLinearImpulse
(
new
Offset
(
randomSignedDouble
()
*
5.0
,
randomSignedDouble
()
*
5.0
),
shipA
.
position
);
Sprite
shipB
;
shipB
=
new
Sprite
(
_spriteSheet
[
"ship.png"
]);
shipB
.
position
=
new
Point
(
pos
.
x
+
40.0
,
pos
.
y
);
shipB
.
size
=
new
Size
(
64.0
,
64.0
);
shipB
.
physicsBody
=
new
PhysicsBody
(
new
PhysicsShapePolygon
([
new
Point
(-
25.0
,
-
25.0
),
new
Point
(
25.0
,
-
25.0
),
new
Point
(
25.0
,
25.0
),
new
Point
(-
25.0
,
25.0
)]),
friction:
0.5
,
tag:
"ship"
);
_physicsNode
.
addChild
(
shipB
);
new
PhysicsJointWeld
(
shipA
.
physicsBody
,
shipB
.
physicsBody
);
}
return
true
;
}
...
...
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