コード例 #1
0
ファイル: Bottle01.cs プロジェクト: WuZongJin/MyGame
        public override void onAddedToScene()
        {
            base.onAddedToScene();

            var texture       = scene.content.Load <Texture2D>("TileMaps/MapTextures/objects");
            var texturePacker = TexturePackerAtlas.create(texture, 32, 32);

            animationTexture[0] = texturePacker.createRegion("1", 64, 96, 32, 32);
            animationTexture[1] = texturePacker.createRegion("2", 96, 96, 32, 32);
            animationTexture[2] = texturePacker.createRegion("3", 128, 96, 32, 32);
            animationTexture[3] = texturePacker.createRegion("4", 160, 96, 32, 32);

            animation = addComponent(new Sprite <BottleAnimation>(animationTexture[0]));
            animation.setLayerDepth(LayerDepthExt.caluelateLayerDepth(this.position.Y));

            animation.addAnimation(BottleAnimation.Idle, new SpriteAnimation(animationTexture[0]));
            var spriteAnimation = new SpriteAnimation(new List <Subtexture>()
            {
                animationTexture[0],
                animationTexture[1],
                animationTexture[2],
                animationTexture[3],
            });

            spriteAnimation.loop = false;
            animation.addAnimation(BottleAnimation.Broke, spriteAnimation);
            animation.onAnimationCompletedEvent += Animation_onAnimationCompletedEvent;

            animation.currentAnimation = BottleAnimation.Idle;
            animation.play(BottleAnimation.Idle);

            var rigidBody = addComponent <FSRigidBody>()
                            .setBodyType(FarseerPhysics.Dynamics.BodyType.Dynamic);

            var shape = addComponent <SceneObjectTriggerComponent>();

            shape.setRadius(5)
            ;

            shape.setCollisionCategories(CollisionSetting.tiledObjectCategory);
            shape.setCollidesWith(CollisionSetting.allAttackCategory | CollisionSetting.allAttackTypeCategory);

            shape.onAdded = onAddedMethod;

            colliderEntity = scene.createEntity("collision");
            colliderEntity.setPosition(this.position);
            colliderEntity.addComponent <FSRigidBody>()
            .setBodyType(BodyType.Static);

            var colliderShape = colliderEntity.addComponent <FSCollisionCircle>();

            colliderShape.setRadius(4);
            colliderShape.setCollisionCategories(CollisionSetting.wallCategory);

            triggerEvent = () =>
            {
                if (!colliderEntity.isDestroyed)
                {
                    colliderEntity.destroy();
                }
            };
        }
コード例 #2
0
        public xObjectTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("Images/ItemsObjects/springObjects");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }
コード例 #3
0
        public yObjectTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("TileMaps/MapTextures/objects");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }
コード例 #4
0
        public xAnimationsTexturePacker()
        {
            var texture = Core.content.Load <Texture2D>("Images/ItemsObjects/animations");

            Packer = TexturePackerAtlas.create(texture, 16, 16);
        }