/////////////////////////////////////////////////////// // // Private Methods // /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// // // Contracts // /////////////////////////////////////////////////////// protected override void FillReserve(int fillSize) { for (int i = fillSize; i > 0; i--) { SpriteCollision newNode = new SpriteCollision(); this.reservedList.PushFront(newNode); } }
/////////////////////////////////////////////////////// // // Methods // /////////////////////////////////////////////////////// /// <summary> /// Create a new flyweight sprite referencing a model SpriteCollision /// </summary> /// <param name="spriteName"></param> /// <param name="id"></param> /// <returns></returns> public SpriteCollisionProxy Create(Sprite.Name spriteName, uint id) { Debug.Assert(spriteName != Sprite.Name.UNINITIALIZED); //Debug.Assert(spriteName != Sprite.Name.NULL); SpriteCollision modelSprite = SpriteCollisionManager.Self.Find(spriteName); Debug.Assert(modelSprite != null, "For some reason, the model collision sprite could not be found!"); SpriteCollisionProxy newProxy = this.BaseCreate(id) as SpriteCollisionProxy; newProxy.SetName(spriteName); newProxy.SetModelSprite(modelSprite); return(newProxy); }
/// <summary> /// Removes the given sprite to be used again from the pool /// </summary> /// <param name="name"></param> /// <returns></returns> public bool Recycle(Sprite.Name name) { Debug.Assert(name != Sprite.Name.UNINITIALIZED); //Debug.Assert(name != Sprite.Name.NULL); SpriteCollision oldNode = this.BaseRecycle(name) as SpriteCollision; if (oldNode == null) { return(false); } oldNode.Reset(); return(true); }
/////////////////////////////////////////////////////// // // Methods // /////////////////////////////////////////////////////// /// <summary> /// Create the sprite from the memory pool /// </summary> /// <param name="newName"></param> /// <returns></returns> public SpriteCollision Create(Sprite.Name newName) { Debug.Assert(newName != Sprite.Name.UNINITIALIZED); //Debug.Assert(newName != Sprite.Name.NULL); if (newName == Sprite.Name.NULL) { SpriteCollision newNullSprite = this.BaseCreate() as SpriteCollision; newNullSprite.SetName(newName); newNullSprite.SetPosition(0, 0); newNullSprite.SetDimensions(5, 5); return(newNullSprite); } SpriteEntity referenceSprite = SpriteEntityManager.Self.Find(newName); SpriteCollision newSprite = this.BaseCreate() as SpriteCollision; newSprite.SetName(newName); newSprite.SetPosition(referenceSprite.X, referenceSprite.Y); newSprite.ResizeToSprite(referenceSprite); return(newSprite); }
/// <summary> /// Clears the data in the Sprite /// </summary> /// <remarks> /// Does not clear base data. Use <c>BaseReset()</c> for that. /// </remarks> public override void Reset() { this.modelSprite = null; //this.SpriteReset(); }
// // Methods // /// <summary> /// Sets the sprite used as a model by the flyweight proxy sprite /// </summary> /// <param name="newSprite"></param> public void SetModelSprite(SpriteCollision newSprite) { this.modelSprite = newSprite; this.SetName(newSprite.SpriteName); }
// // Constructors // public SpriteCollisionProxy() : base() { this.modelSprite = null; this.width = 5; this.height = 5; }