Exemplo n.º 1
0
        /// <summary>
        ///		Setup the boundaries and position of this collider given a sprite
        /// </summary>
        /// <param name="theProxy"></param>
        public void SetupCollisonSpriteProxy(SpriteProxy theProxy)
        {
            SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);

            // Remove previous SpriteCollisionProxy if any
            if (this.collisionSprite != null)
            {
                bool oldProxyRemoved = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
                Debug.Assert(oldProxyRemoved, "The old collision sprite proxy wasn't removed upon setting a new proxy!");
                Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED);
                SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
                this.collisionSprite = null;
            }

            // Create a new proxy
            this.collisionSprite = SpriteCollisonProxyManager.Active.Create(theProxy.SpriteName, theProxy.Id);
            this.collisionSprite.SetId(theProxy.Id);
            this.collisionSprite.SetPosition(this.colliderBoundary.x, this.colliderBoundary.y);
            this.colliderBoundary.w = this.collisionSprite.ModelSprite.Width;
            this.colliderBoundary.h = this.collisionSprite.ModelSprite.Height;
            this.collisionSprite.SetColor(this.color);

            // Attach it to the batch
            colliderBatch.Attach(this.collisionSprite, this.collisionSprite.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        ///		Setup the boundaries and position of this collider given a width and height
        /// </summary>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void SetupCollisonSpriteProxy(float width, float height, uint newId)
        {
            SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);

            // Remove previous SpriteCollisionProxy if any
            if (this.collisionSprite != null)
            {
                bool oldRemSuccess = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
                Debug.Assert(oldRemSuccess, "Upon setting a new collider sprite proxy, the old one was not deleted!");
                Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED);
                SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
                this.collisionSprite = null;
            }

            // Create a new proxy
            this.collisionSprite = SpriteCollisonProxyManager.Active.Create(Sprite.Name.NULL, newId);
            this.collisionSprite.SetId(newId);
            this.collisionSprite.SetPosition(this.colliderBoundary.x, this.colliderBoundary.y);
            this.collisionSprite.Resize(width, height);
            this.colliderBoundary.w = width;
            this.colliderBoundary.h = height;
            this.collisionSprite.SetColor(this.color);

            // Attach it to the batch
            colliderBatch.Attach(this.collisionSprite, this.collisionSprite.Id);
        }
Exemplo n.º 3
0
        /// <summary>
        ///		Changes the sprite reference
        /// </summary>
        /// <param name="newSprite"></param>
        public void SetSprite(SpriteBatch.Name newBatchName, SpriteEntity newSprite)
        {
            // Remove the old sprite from it's sprite batch
            SpriteBatch oldBatch = SpriteBatchManager.Active.Find(this.batchName);

            if (oldBatch != null)
            {
                bool su = oldBatch.Detach(this.sprite.SpriteName, this.sprite.Id);
                Debug.Assert(su, "The old SpriteBatch has to detach a valid (non-null) sprite.");
            }

            // Recycle old sprite
            SpriteProxyManager.Active.Recycle(this.sprite.SpriteName, this.sprite.Id);
            this.sprite = null;

            // Get new batch
            SpriteBatch newBatch = SpriteBatchManager.Active.Find(newBatchName);

            this.batchName = newBatchName;

            // If null, get null proxy and leave
            if (newBatch == null)
            {
                this.sprite = SpriteProxyManager.Active.NullSpriteProxy;
                return;                 // Leave
            }

            // Get new sprite and attach it
            this.sprite = SpriteProxyManager.Active.Create(newSprite.SpriteName, this.Id);
            newBatch.Attach(this.sprite, this.sprite.Id);

            this.collider.SetupCollisonSpriteProxy(this.sprite);
        }
Exemplo n.º 4
0
 /// <summary>
 ///		Makes the collider null so that it doesn't
 ///		render a SpriteCollison or check collisions
 /// </summary>
 public void MakeColliderNull()
 {
     // Remove previous SpriteCollisionProxy if any
     if (this.collisionSprite != null)
     {
         SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);
         bool        colSprRemoved = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
         Debug.Assert(colSprRemoved, "This collision sprite proxy wasn't removed for some reason!");
         Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED);
         SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
         this.collisionSprite = null;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///		Reset function that can only be called by the base GameObject!
        /// </summary>
        public void Reset()
        {
            // Remove previous SpriteCollisionProxy if any
            if (this.collisionSprite != null)
            {
                SpriteBatch colliderBatch = SpriteBatchManager.Active.Find(SpriteBatch.Name.SpriteCollisions);
                bool        success       = colliderBatch.Detach(collisionSprite.SpriteName, collisionSprite.Id);
                Debug.Assert(success, "The collision sprite proxy wasn't found during collider's reset!");
                Debug.Assert(this.collisionSprite.SpriteName != Sprite.Name.UNINITIALIZED, "The collision sprite proxy already seems to be uninitialized, but it's probably not");
                SpriteCollisonProxyManager.Active.Recycle(collisionSprite.SpriteName, collisionSprite.Id);
                this.collisionSprite = null;
            }

            this.gameObjectId = 0u;
            this.color        = Colors.Yellow;
        }
Exemplo n.º 6
0
        /// <summary>
        ///		Clears the data in the GameObject. Base must be called if overriding!
        /// </summary>
        public void Reset()
        {
            this.wasAlreadyRemoved = true;

            this.OnDestroy();

            // Get the parent of this GameObject
            GameObject parent = this.Parent as GameObject;

            this.RemoveThisPCSNode();

            // Do post-delete procedure of the parent's collider
            if (parent != null)
            {
                parent.ReevaluateCollider();
            }

            this.ResetAnimator();

            this.collider.Reset();

            // Remove the old sprite from it's sprite batch
            SpriteBatch oldBatch = SpriteBatchManager.Active.Find(this.batchName);

            if (oldBatch != null)
            {
                bool su = oldBatch.Detach(this.sprite.SpriteName, this.sprite.Id);
                Debug.Assert(su, "The old SpriteBatch has to detach a valid (non-null) sprite.");
            }

            SpriteProxyManager.Active.Recycle(this.sprite.SpriteName, this.sprite.Id);
            this.sprite = SpriteProxyManager.Active.NullSpriteProxy;

            this.name       = GameObject.Name.UNINITIALIZED;
            this.batchName  = SpriteBatch.Name.UNINITIALIZED;
            this.color      = Colors.White;
            this.x          = 0.0f;
            this.y          = 0.0f;
            this.instanceId = 0u;
        }