Represents a 2D Image.
Inheritance: Component
コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpriteRenderer" /> class.
 /// </summary>
 /// <param name="layerType">
 /// Layer type (available at <see cref="DefaultLayers"/>).
 /// Example: new SpriteRenderer(DefaultLayers.Alpha)
 /// </param>
 /// <param name="samplerMode">
 /// Sampler mode <see cref="AddressMode"/>
 /// Example: new SpriteRenderer(DefaultLayers.Alpha)
 /// </param>
 public SpriteRenderer(Type layerType, AddressMode samplerMode = AddressMode.LinearClamp)
     : base("SpriteRenderer" + instances++, layerType)
 {
     this.Transform2D = null;
     this.Sprite = null;
     this.samplerMode = samplerMode;            
 }
コード例 #2
0
 private void UpdateSpriteComponent(string spritePath)
 {
     this.entity.RemoveComponent<Sprite>();
     var newSpriteComponent = new Sprite(spritePath);
     this.entity.AddComponent(newSpriteComponent);
     this.entity.RefreshDependencies();
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnimatedSpriteRenderer" /> class.
 /// </summary>
 /// <param name="layer">Layer type.</param>
 /// <param name="samplerMode">The sampler mode.</param>
 public AnimatedSpriteRenderer(Type layer, AddressMode samplerMode = AddressMode.LinearClamp)
     : base("AnimatedSpriteRenderer" + instances++, layer)
 {
     this.Transform2D = null;
     this.Sprite = null;            
     this.Animation2D = null;
     this.samplerMode = samplerMode;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpriteRenderer" /> class.
 /// </summary>
 /// <param name="layerType">Type of the layer.</param>
 public SpriteRenderer(Type layerType)
     : base("SpriteRenderer" + instances++, layerType)
 {
     this.Transform2D = null;
     this.Sprite = null;
     this.scale = Vector2.Zero;
     this.position = Vector2.Zero;
     this.origin = Vector2.Zero;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnimatedSpriteRenderer" /> class.
 /// </summary>
 /// <param name="layer">Layer type.</param>
 public AnimatedSpriteRenderer(Type layer)
     : base("AnimatedSpriteRenderer" + instances++, layer)
 {
     this.Transform2D = null;
     this.Sprite = null;
     this.scale = Vector2.Zero;
     this.position = Vector2.Zero;
     this.origin = Vector2.Zero;
     this.Animation2D = null;
 }
コード例 #6
0
        /// <summary>
        /// Creates the ball.
        /// </summary>
        private void CreateBall()
        {
            int index = WaveServices.Random.NextBool() ? 1 : 0;
            string textureName = ballTextures[index];

            this.ball = new Entity("ball" + ball_instances++)
            {
                Tag = "ball"
            }
            .AddComponent(new Transform2D()
            {
                Origin = Vector2.Center,
                X = WaveServices.Random.Next(400, 900),
                Y = WaveServices.Random.Next(370, 580),
                DrawOrder = 0.4f,
            })
            .AddComponent(new CircleCollider2D())
            .AddComponent(new Sprite(textureName)
            {
                //TintColor = Color.Yellow,
            })
            .AddComponent(new BallBehavior())
            .AddComponent(new RigidBody2D()
            {
                PhysicBodyType = PhysicBodyType.Static,
                CollisionCategories = Physic2DCategory.Cat2,
                CollidesWith = Physic2DCategory.None,
                Restitution = 0.6f,
            })
            .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));

            this.gamePlayScene.EntityManager.Add(this.ball);

            this.ballTransform = this.ball.FindComponent<Transform2D>();
            this.rigidBodyBall = this.ball.FindComponent<RigidBody2D>();
            this.ballSprite = this.ball.FindComponent<Sprite>();

            // Collision
            this.rigidBodyBall.OnPhysic2DCollision += (s, o) =>
            {
                if (o.Body2DB.Owner.Tag == "Border")
                {
                    this.gamePlayScene.EntityManager.Remove(o.Body2DA.Owner);

                }
            };

            // Start Position
            this.startTransform.X = this.ballTransform.X;
            this.startTransform.Y = this.ballTransform.Y;            
        }