/// <summary>
        /// Renders the GUI for the sprite
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="renderer">Renderer</param>
        /// <param name="batch">Sprite batch</param>
        public override void OnGUI(GameTime gameTime, Renderer renderer, SpriteBatch batch)
        {
            // Calculate the position of the sprite by flipping the y-coordinate
            Vector2 renderPosition = renderer.YCoordinateFlip(_owner.Position);
            renderPosition.Y -= _sprite.Height / 2.0f;

            // Render the sprite
            renderer.WriteText(batch, renderPosition, Owner.Name);

            base.OnRender(gameTime, renderer, batch);
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Initialize the graphics
            _renderer = new Renderer(graphics);

            // Initialize the scene root
            _root = new SceneNode(null, "_root_");

            // Add a test sprite
            SceneNode node = new SceneNode(_root, "Test Node");
            SpriteAttachment spriteAttachment = new SpriteAttachment(node, new Sprite(Content.Load<Texture2D>("sting"), new Vector2(64, 96)));
            node.Position = new Vector2(200.0f, 200.0f);

            base.Initialize();
        }
        /// <summary>
        /// Renders the sprite
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="renderer">Renderer</param>
        /// <param name="batch">SpriteBatch to draw the sprite</param>
        /// <param name="position">The position </param>
        public override void Render(GameTime gameTime, Renderer renderer, SpriteBatch batch, Vector2 position)
        {
            Tuple<int, int> frame = CurrentFrame;
            int row = frame.Item1;
            int column = frame.Item2;

            Rectangle destination = new Rectangle((int)position.X, (int)position.Y, Width, Height);
            Rectangle source = new Rectangle(Width * column, Height * row, Width, Height);
            batch.Draw(Texture, destination, source, Color.White);
        }
Example #4
0
 /// <summary>
 /// Renders the sprite
 /// </summary>
 /// <param name="gameTime">Game time</param>
 /// <param name="renderer">Renderer</param>
 /// <param name="batch">SpriteBatch to draw the sprite</param>
 /// <param name="position">The position </param>
 public virtual void Render(GameTime gameTime, Renderer renderer, SpriteBatch batch, Vector2 position)
 {
     batch.Draw(Texture, new Rectangle((int)position.X, (int)position.Y, Width, Height), Color.White);
 }
 /// <summary>
 /// Renders the scene node
 /// </summary>
 /// <param name="gameTime">Elapsed game time</param>
 /// <param name="renderer">Renderer</param>
 /// <param name="batch">SpriteBatch used for rendering</param>
 public virtual void OnRender(GameTime gameTime, Renderer renderer, SpriteBatch batch)
 {
 }
        /// <summary>
        /// Renders the scene node
        /// </summary>
        /// <param name="gameTime">Elapsed game time</param>
        /// <param name="renderer">Renderer</param>
        /// <param name="batch">SpriteBatch used for rendering</param>
        public virtual void OnRender(GameTime gameTime, Renderer renderer, SpriteBatch batch)
        {
            // Render all the attachments
            foreach (SceneNodeAttachment attachment in _attachments)
            {
                attachment.OnRender(gameTime, renderer, batch);
            }

            // Render the children
            foreach (SceneNode child in Children)
            {
                child.OnRender(gameTime, renderer, batch);
            }
        }