Click here to Skip to main content
15,884,629 members
Articles / Multimedia / DirectX

Endogine sprite engine

Rate me:
Please Sign up or sign in to vote.
4.84/5 (53 votes)
17 Jul 200615 min read 715.3K   22.1K   216  
Sprite engine for D3D and GDI+ (with several game examples).
using System;
using System.Collections.Generic;
using System.Text;

namespace Endogine.Forms
{
    public class MeterXY : Sprite
    {
        Endogine.Tools.Relay _relay;
        Sprite _indicator;
        public Endogine.Tools.RangeConverter RangeX;
        public Endogine.Tools.RangeConverter RangeY;

        public MeterXY()
        {
            this.SourceRect = new ERectangle(0, 0, 1, 1);

            this.RangeX = new Endogine.Tools.RangeConverter();
            this.RangeY = new Endogine.Tools.RangeConverter();

            this._indicator = new Sprite();
            this._indicator.Parent = this;
            this._indicator.Member = new MemberSpriteBitmap(
                Endogine.BitmapHelpers.BitmapHelper.CreateFilledBitmap(new EPoint(4, 1),
                System.Drawing.Color.FromArgb(255, 255, 255)));
        }

        public override void EnterFrame()
        {
            this._relay.Update();
        }
        public override ERectangleF Rect
        {
            get
            {
                return base.Rect;
            }
            set
            {
                base.Rect = value;
                this.RangeX.MaxOut = 1f/value.Width;
                this.RangeY.MaxOut = 1f/value.Height;
                this._indicator.Scaling = new EPointF(1f / value.Width, 1f / value.Height);
            }
        }

        public void SetAutoFetch(object o, string property)
        {
            this._relay = new Endogine.Tools.Relay(o, property, this, "Value");
        }

        public EPointF Value
        {
            get { return new EPointF(); }
            set
            {
                EPointF loc = new EPointF(
                    this.RangeX.ConvertInToOut(value.X),
                    this.RangeY.ConvertInToOut(value.Y));

                EPointF mid = new EPointF(
                    this.RangeX.ConvertInToOut(0),
                    this.RangeY.ConvertInToOut(0));

                EPointF diff = loc - mid;
                this._indicator.ScaleX = diff.Length;
                this._indicator.Rotation = diff.Angle;
                this._indicator.Loc = mid;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions