当前位置: 首页>>代码示例>>C#>>正文


C# CollisionObject.SetOffset方法代码示例

本文整理汇总了C#中CollisionObject.SetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# CollisionObject.SetOffset方法的具体用法?C# CollisionObject.SetOffset怎么用?C# CollisionObject.SetOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CollisionObject的用法示例。


在下文中一共展示了CollisionObject.SetOffset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Create

        public static Node Create(string name, string texture, Vector3 pos)
        {
            var cmp = new MyTarget ();

            var spr = new Sprite (64, 128);
            spr.AddTexture (new Texture (texture));

            var col = new CollisionObject ();
            col.Shape = new BoxShape (spr.Width/2, spr.Height/2, 100);
            col.SetOffset (spr.Width/2, spr.Height/2, 0);

            var mbox1 = new MailBox ("MouseSelect");
            var mbox2 = new MailBox ("MouseDeselect");

            var node = new Node (name);
            node.Attach (cmp);
            node.Attach (col);
            node.Attach (spr);
            node.Attach (mbox1);
            node.Attach (mbox2);

            node.Translation = pos;

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:25,代码来源:MyTarget.cs

示例2: Create

        public static Node Create(string name, string address, Vector3 pos)
        {
            var cmp = new MyButton ();
            cmp.address = address;

            var spr = new Sprite (32, 32);
            spr.AddTexture (Resource.GetDefaultTexture ());

            var label = new Label ();
            label.Text = name;
            label.Color = Color.Black;
            label.SetOffset (8, 8);

            var col = new CollisionObject ();
            col.Shape = new BoxShape(16, 16, 16);
            col.SetOffset (16, 16, 16);

            var node = new Node (name);
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (label);
            node.Attach (col);

            node.Translation = pos;

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:27,代码来源:MyButton.cs

示例3: Create

        public static Node Create(string fileName)
        {
            var cmp = new MyTiledMap ();

            var tiledMap = new TiledMapComposer ();

            var node = new Node ("TiledMap");
            node.Attach (tiledMap);
            node.Attach (cmp);

            tiledMap.LoadFromFile (fileName);

            var halfWidth = tiledMap.TileWidth / 2;
            var halfHeight = tiledMap.TileHeight / 2;

            // コリジョンなどのゲームロジックはすべて
            // 仮想の2D直交座標系で作成する
            // 表示だけアイソメトリック
            var colMap = node.Find("CollisionMap");
            foreach (var tile in colMap.Downwards.Skip(1)) {
                var col = new CollisionObject();
                col.Shape = new BoxShape (halfWidth, halfHeight, 1);
                col.SetOffset (halfWidth, halfHeight, 1);

                tile.Attach (col);
            }

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:29,代码来源:MyTiledMap.cs

示例4: Create

        public static Node Create(Vector3 pos)
        {
            var cmp = new MyComponent ();

            var spr = new Sprite (480, 300);
            spr.AddTexture (new Texture ("media/Vanity.jpg"));
            spr.AddTexture (new Texture ("media/Tanks.png"));
            spr.AddTexture (new Texture ("media/TatamiRoom.png"));
            spr.AutoScale = true;

            Console.WriteLine ("tex = " + spr.GetTexture (0));
            Console.WriteLine ("spr = " + spr);

            var col = new CollisionObject();
            col.Shape  = new BoxShape(spr.Width/2, spr.Height/2, 100);
            col.SetOffset (spr.Width/2, spr.Height/2, 0);

            var ctr = new AnimationController ();

            var node = new Node ();
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (col);
            node.Attach (ctr);

            node.Translation = pos;

            var clip = new SoundClip ("Sound");
            clip.AddTrack (new SoundEffectTrack ("media/PinPon.wav"));

            node.UserData.Add (clip.Name, clip);

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:34,代码来源:MyComponent.cs

示例5: Create

        public static Node Create(Vector3 pos)
        {
            var cmp = new MySprite ();

            var spr = new Sprite (64, 64);
            spr.AddTexture (new Texture ("media/Box-64x64.png"));

            var col = new CollisionObject ();
            col.Shape = new BoxShape (spr.Width / 2, spr.Height / 2, 100);
            col.SetOffset (spr.Width / 2, spr.Height / 2, 0);

            var mbox1 = new MailBox ("MouseSelect");
            var mbxo2 = new MailBox ("MouseDeselect");

            var node = new Node ("MySprite");
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (col);
            node.Attach (mbox1);
            node.Attach (mbxo2);

            node.Translation = pos;

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:25,代码来源:MySprite.cs

示例6: Test_BoxShape

        public void Test_BoxShape()
        {
            var node = new Node ();

            var col = new CollisionObject ();
            col.Shape = new BoxShape (1, 1, 1);
            col.SetOffset (1, 0, 0);
            node.Attach (col);

            node.Translate (1, 0, 0);
            node.Rotate (45, 0, 0, 1);

            var wld = new World ();
            wld.AddChild (node);

            wld.CollisionUpdate ();

            // (1+1) - 1*√2
            var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (0.5858f, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (10.58579f, result.Distance, 0.01f);
            Assert.AreEqual (0.5245f, result.Fraction, 0.01f);

            // (1+1) + 1*√2
            result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (3.4142f, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
            Assert.AreEqual (6.585786f, result.Distance, 0.01f);
            Assert.AreEqual (0.3225f, result.Fraction, 0.01f);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:35,代码来源:TestRayCast.cs

示例7: Create

        public static Node Create(Vector3 pos, int collisionMask)
        {
            var cmp = new MyBlock ();

            var spr = new Sprite (128, 64);
            spr.AddTexture (Resource.GetDefaultTexture ());
            spr.Color = Color.Cyan;

            var col = new CollisionObject ();
            col.Shape = new BoxShape (spr.Width/2, spr.Height/2, 1);
            col.SetOffset (spr.Width/2, spr.Height/2, 1);
            col.CollideWith = collisionMask;

            var label = new Label ();
            label.Text = "Mask = 0x" + collisionMask.ToString("x");

            var node = new Node ("Block");
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (col);
            node.Attach (label);

            node.Translation = pos;

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:26,代码来源:MyBlock.cs

示例8: Test_Distance_Box_to_Box

        public void Test_Distance_Box_to_Box()
        {
            var node1 = new Node ("Node1");

            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            col1.SetOffset (0, 0, 0);

            node1.Attach (col1);

            var node2 = new Node ("Node2");
            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (1,1,1);
            col2.SetOffset (0, 10, 0);

            node2.Attach (col2);

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);

            // 10*√2

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);

            wld.CollisionUpdate ();

            Assert.AreEqual(10*1.4142f - 2*1.4142f, wld.Distance (node1, node2), 0.05f);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:32,代码来源:TestDistance.cs

示例9: Test_BoxShape

        public void Test_BoxShape()
        {
            var node1 = new Node ("Sweeper");

            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            col1.SetOffset (0, 1, 0);

            node1.Attach (col1);

            var node2 = new Node ("Target1");
            var col2 = new CollisionObject ();
            col2.Shape = new SphereShape (1);
            col2.SetOffset (0, 1, 0);

            node2.Attach (col2);

            var node3 = new Node ("Target2");
            var col3 = new CollisionObject ();
            col3.Shape = new SphereShape (1);
            col3.SetOffset (0, 1, 0);

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);
            node3.Translate (20, 0, 0);

            var wld = new World ();
            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);

            wld.CollisionUpdate ();

            var result = wld.Sweep (node1, new Vector3 (100, 0, 0));
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (9, 1, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (8, result.Distance, 0.01f);
            Assert.AreEqual (0.08f, result.Fraction, 0.01f);

            result = wld.Sweep (node1, new Vector3 (0, 100, 0));
            Assert.AreEqual (false, result.Hit);

            result = wld.Sweep (node1, new Vector3 (-100, 100, 0));
            Assert.AreEqual (false, result.Hit);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:48,代码来源:TestSweep.cs

示例10: Create

        public static World Create(float width, float height)
        {
            var cmp = new MyWorld ();

            var spr = new Sprite ();
            spr.AddTexture(new Texture ("media/Vanity.jpg"));

            var col = new CollisionObject ();
            col.Shape = new BoxShape (width / 2, height / 2, 1);
            col.SetOffset (width / 2, height / 2, 0);

            var node = new World ("MyWorld");
            node.Attach (cmp);
            node.Attach (col);
            node.Attach (spr);

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:18,代码来源:MyWorld.cs

示例11: Create

        public static Node Create(string name, Vector3 pos)
        {
            var cmp = new MyCharacterButton (name);

            var spr = new Sprite (128, 64);
            spr.AddTexture (Resource.GetDefaultTexture ());

            var label1 = new Label ();
            label1.Text = cmp.dbCharacter.FullName;
            label1.SetOffset (10, 10);
            label1.Color = Color.Black;

            var label2 = new Label ();
            label2.Text = cmp.dbCharacter.FullNameYomi;
            label2.SetOffset (10, 30);
            label2.Color = Color.Black;

            var col = new CollisionObject ();
            col.Shape = new BoxShape (64, 32, 100);
            col.SetOffset (64, 32, 0);

            var snd = new SoundEffectTrack ("media/PinPon.wav");
            var clip = new SoundClip ("クリック音");
            clip.AddTrack (snd);

            var node = new Node ("Button(" + name + ")");
            node.Attach (cmp);
            node.Attach (spr);
            node.Attach (label1);
            node.Attach (label2);
            node.Attach (col);

            node.UserData.Add (clip.Name, clip);

            node.Translation = pos;
            node.DrawPriority = -1;

            return node;
        }
开发者ID:weimingtom,项目名称:erica,代码行数:39,代码来源:MyCharacterButton.cs

示例12: Test_SetOffset

        public void Test_SetOffset()
        {
            var col = new CollisionObject ();

            col.Offset = new Vector3 (1, 2, 3);
            Assert.AreEqual (new Vector3(1,2,3), col.Offset);

            col.SetOffset (4, 5, 6);
            Assert.AreEqual (new Vector3 (4, 5, 6), col.Offset);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:10,代码来源:TestCollisionObject.cs

示例13: Test_Sweep

        public void Test_Sweep()
        {
            var node1 = new Node ("Node1");
            var col1 = new CollisionObject ();
            col1.Shape = new BoxShape (1, 1, 1);
            node1.Attach (col1);
            node1.Rotate (45, 0, 0, 1);
            node1.Rotate (45, 1, 0, 0);

            var node2 = new Node ("Node2");
            var col2 = new CollisionObject ();
            col2.Shape = new BoxShape (2, 2, 2);
            col2.Offset = new Vector3 (2, 0, 0);
            node2.Attach (col2);

            var node3 = new Node ("Node3");
            var col3 = new CollisionObject ();
            col3.Shape = new BoxShape (1, 1, 1);
            col3.SetOffset (-1, 0, 0);
            node3.Attach (col3);

            var wld = new World ("World");
            wld.AddChild (node1);
            wld.AddChild (node2);
            wld.AddChild (node3);

            node1.Translate (0, 0, 0);
            node2.Translate (10, 0, 0);
            node3.Translate (-10, 0, 0);

            wld.CollisionUpdate ();

            var result = wld.Sweep (node1, new Vector3 (100, 0, 0));
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (10, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (8.602f, result.Distance, 0.01f);
            Assert.AreEqual (0.09f, result.Fraction, 0.01f);

            result = wld.Sweep (node1, new Vector3 (-100, 0, 0));
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (-10, 0.2812f, -0.2812f), result.Point);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
            Assert.AreEqual (8.602f, result.Distance, 0.01f);
            Assert.AreEqual (0.09f, result.Fraction, 0.01f);
        }
开发者ID:weimingtom,项目名称:erica,代码行数:46,代码来源:TestCollisionAnalyze.cs

示例14: Test_SphereShape

        public void Test_SphereShape()
        {
            var node = new Node ();

            var col = new CollisionObject ();
            col.Shape = new SphereShape (1);
            col.SetOffset (1, 0, 0);
            node.Attach (col);

            node.Translate (1, 0, 0);
            node.Rotate (45, 0, 0, 1);

            var wld = new World ();
            wld.AddChild (node);

            wld.CollisionUpdate ();

            // (1+1) - 1
            var result = wld.RayCast (new Vector3 (-10, 0, 0), new Vector3 (10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (-1, 0, 0), result.Normal);
            Assert.AreEqual (11, result.Distance, 0.01f);
            Assert.AreEqual (0.55f, result.Fraction, 0.01f);

            // (1+1) + 1
            result = wld.RayCast (new Vector3 (10, 0, 0), new Vector3 (-10, 0, 0)).First ();
            Assert.AreEqual (true, result.Hit);
            Assert.AreEqual (new Vector3 (3, 0, 0), result.Point);
            Assert.AreEqual (new Vector3 (1, 0, 0), result.Normal);
            Assert.AreEqual (7, result.Distance, 0.01f);
            Assert.AreEqual (0.35f, result.Fraction, 0.01f);

            wld.Destroy ();
        }
开发者ID:weimingtom,项目名称:erica,代码行数:35,代码来源:TestRayCast.cs


注:本文中的CollisionObject.SetOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。