コード例 #1
0
ファイル: GDMainEngine.cs プロジェクト: LuizZak/GDEngine
        /// <summary>
        /// Initializes a new instance of the GDMainEngine, and prepares the engine to be used in a game
        /// </summary>
        /// <param name="game">The Game instance that is using this engine</param>
        /// <param name="device">The GraphicsDevice object that will be used to initialize graphics during the game</param>
        public GDMainEngine(Game game, GraphicsDevice device)
        {
            // Assign some starting variables
            Game = game;

            Device = device;

            Width  = device.PresentationParameters.BackBufferWidth;
            Height = device.PresentationParameters.BackBufferHeight;

            RenderTarget = new RenderTarget2D(Device, Width, Height, true, device.PresentationParameters.BackBufferFormat, DepthFormat.Depth24);

            Device.SetRenderTarget(null);

            Root        = new GDEntity(0, 0, Width, Height, this);
            Root.isRoot = true;

            Removed = new List <GDEntity>();

            Camera = new GDCamera(0, 0, Width, Height);

            // Generate the 1x1 pixel texture
            if (GDTextureFactory.PixelTexture == null)
            {
                GDTextureFactory.PixelTexture = new Texture2D(device, 1, 1);
                GDTextureFactory.PixelTexture.SetData <Color>(new Color[] { Color.White });
            }

            // Set the content providers device
            GDContent.device = device;

            // Set the statics GraphicsDevice value
            GDStatics.Device = device;
        }
コード例 #2
0
ファイル: GDScreen.cs プロジェクト: LuizZak/GDEngine
        /// <summary>
        /// Called when the screen is first initialized
        /// </summary>
        public virtual void Init()
        {
            Root        = new GDEntity();
            Root.isRoot = true;
            Root.Engine = MainEngine;

            eventHandler = new GDDefaultEventHandler();
        }
コード例 #3
0
ファイル: GDMainEngine.cs プロジェクト: LuizZak/GDEngine
        /// <summary>
        /// Adds an entity to the root entity's children list
        /// </summary>
        /// <param name="newChild">The new children to add</param>
        /// <returns>The entity created</returns>
        public GDEntity addChild(GDEntity newChild)
        {
            if (CurrentScreen != null)
            {
                CurrentScreen.Root.addChild(newChild);
            }
            else
            {
                Root.addChild(newChild, -1);
            }

            return(newChild);
        }
コード例 #4
0
 /// <summary>
 /// Gets the index of the given Link into the List
 /// </summary>
 /// <param name="Entity">The entity to search for binding</param>
 /// <param name="currentIndex">Current index, used to return the index</param>
 /// <returns>The index of the Link in the list</returns>
 public int IndexOf(GDEntity Entity, int currentIndex)
 {
     if (this.Entity == Entity)
     {
         return(currentIndex);
     }
     else if (Next != null)
     {
         if (Next.Entity == Entity) // Let's skip a function call right here...
         {
             return(currentIndex + 1);
         }
         else
         {
             return(Next.IndexOf(Entity, currentIndex + 1));
         }
     }
     else
     {
         return(-1);
     }
 }
コード例 #5
0
        /// <summary>
        /// Gets the Link with the given entity binded
        /// </summary>
        /// <param name="entity">The entity to search for binding</param>
        /// <returns>The Link, or null if not found</returns>
        public GDDisplayLinkedListLink GetNextLink(GDEntity entity)
        {
            if (entity == Entity)
            {
                return(this);
            }

            GDDisplayLinkedListLink link = this;

            while (link != null)
            {
                if (entity == link.Entity)
                {
                    return(link);
                }

                link = link.Next;
            }

            return(null);

            throw new IndexOutOfRangeException("Child index is outside of bounds");
        }
コード例 #6
0
 /// <summary>
 /// Creates a new instance of the GDDisplayLinkedListLink class
 /// </summary>
 /// <param name="entity">An GDEntity that will be associated to this Link</param>
 public GDDisplayLinkedListLink(GDEntity entity)
 {
     Entity = entity;
 }
コード例 #7
0
 /// <summary>
 /// Gets a Link on the given index
 /// </summary>
 /// <param name="index">The entity to use as search index</param>
 /// <returns>The Link, or null if out of the bounds</returns>
 public GDDisplayLinkedListLink this[GDEntity index]
 {
     get { return(List == null ? null : List.GetNextLink(index)); }
 }
コード例 #8
0
 /// <summary>
 /// Returns the index at which the given GDEntity resides
 /// </summary>
 /// <param name="Entity">The GDEntity to search for</param>
 /// <returns>At which the given entity resides</returns>
 public int IndexOf(GDEntity Entity)
 {
     return(List == null ? -1 : List.IndexOf(Entity, 0));
 }
コード例 #9
0
 /// <summary>
 /// Removes the given GDEntity from the list
 /// </summary>
 /// <param name="Entity">The GDEntity to remove</param>
 public GDDisplayLinkedListLink Remove(GDEntity Entity)
 {
     return(Remove(Entity.Link));
 }
コード例 #10
0
 /// <summary>
 /// Add the given GDEntity into the list
 /// </summary>
 /// <param name="Entity">The GDEntity to add to the list</param>
 /// <param name="index">The index at which to insert this entity. Leave -1 to push to the end of the list</param>
 /// <exception cref="ArgumentException">The GDEntity.Link already has a parent list</exception>
 public void Add(GDEntity Entity, int index = -1)
 {
     Add(Entity.Link, index);
 }
コード例 #11
0
 /// <summary>
 /// Returns the distance between the two given entities
 /// </summary>
 /// <param name="entity1">A valid GDEntity that has the same parent as the second entity</param>
 /// <param name="entity2">A valid GDEntity that has the same parent as the first entity</param>
 /// <returns>The distance between the given entities</returns>
 public static float Distance(GDEntity entity1, GDEntity entity2)
 {
     return(Vector2.Distance(entity1.position, entity2.position));
 }