Revision | 752 (tree) |
---|---|
Zeit | 2011-02-22 14:11:49 |
Autor | massa_senohito |
RigidBodyに潜むバグを潰した
SpriteBodyにfront等追加、bodyが512超えそうになるとbody生成をやめます(削除予定)
@@ -14,6 +14,7 @@ | ||
14 | 14 | public SpriteBody(Sprite sprite, IEnumerable<SpriteShape> shapes, Vec2 position) |
15 | 15 | { |
16 | 16 | this.position = position; |
17 | + if (GameMap.World.GetBodyCount() > 511) return; | |
17 | 18 | |
18 | 19 | switch (sprite.LayerType) |
19 | 20 | { |
@@ -20,15 +21,31 @@ | ||
20 | 21 | //キャラクターの場合、sprite.Shape.Width, sprite.Shape.Heightから値をとっている |
21 | 22 | //myUserDataは決まっていない |
22 | 23 | case Nlgp1.Common.LayerType.Character: |
23 | - DynamicRigid chara = new DynamicRigid(position, 0, liniervelocity, angulervelocity); | |
24 | - chara.SetAsBox(sprite.Shape.Width, sprite.Shape.Height, new Polygondef2(friction, restitution, density, new myUserData()), false); | |
25 | - chara.MakeBody(GameMap.World); | |
24 | + foreach (SpriteShape ss in shapes) | |
25 | + { | |
26 | + Vec2 lb = ss.AABB.UpperBound - ss.AABB.LowerBound; | |
27 | + lb.X /= 2; lb.Y /= 2; | |
28 | + DynamicRigid chara = new DynamicRigid(position, 0, liniervelocity, angulervelocity); | |
29 | + chara.SetAsBox(lb.X, lb.Y, new Polygondef2(friction, restitution, density, new myUserData()), false); | |
30 | + chara.MakeBody(GameMap.World); | |
31 | + } | |
26 | 32 | break; |
33 | + case Nlgp1.Common.LayerType.Front: | |
34 | + foreach (SpriteShape ss in shapes) | |
35 | + { | |
36 | + Vec2 lb = ss.AABB.UpperBound - ss.AABB.LowerBound; | |
37 | + lb.X /= 2; lb.Y /= 2; | |
38 | + StaticRigid chara = new StaticRigid(position, 0, 0, 0); | |
39 | + chara.SetAsBox(lb.X, lb.Y, new Polygondef2(3,0,0, new myUserData()), false); | |
40 | + chara.MakeBody(GameMap.World); | |
41 | + } | |
42 | + break; | |
27 | 43 | default: |
28 | 44 | break; |
29 | 45 | } |
30 | 46 | } |
31 | 47 | public void Act() { |
48 | + | |
32 | 49 | } |
33 | 50 | |
34 | 51 | public Vec2 Position { |
@@ -196,7 +196,7 @@ | ||
196 | 196 | { |
197 | 197 | SelfBody.CreateShape(pd); |
198 | 198 | }); |
199 | - if (!this.BodyKind.Equals("Static")) | |
199 | + if (!this.BodyKind.Contains("Static")) | |
200 | 200 | { |
201 | 201 | SelfBody.SetMassFromShapes(); |
202 | 202 | } |