/// <summary>
        /// Creates a new bitmap font.
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="charWidth">Width in pixels of characters</param>
        /// <param name="charHeight">Height in pixels of characters</param>
        /// <param name="chars">Characters in the order they appear in the bitmap</param>
        public BitmapFont(string assetName, int charWidth, int charHeight, string chars)
        {
            this.AssetName   = assetName;
            this.charWidth   = charWidth;
            this.charHeight  = charHeight;
            this.chars       = chars;
            this.sfcChars    = new SpriteFrameCache();
            this.CharSpacing = charWidth;

            Texture2D texture = SosEngine.Core.GetTexture(assetName);

            // Create sprite frame for each character
            int charsH    = texture.Width / charWidth;
            int charsV    = texture.Height / charHeight;
            int charIndex = 0;

            for (int y = 0; y < charsV; y++)
            {
                for (int x = 0; x < charsH; x++)
                {
                    sfcChars.AddSpriteFrame(new SpriteFrame(assetName, "char_" + charIndex.ToString(), new Rectangle(x * charWidth, y * charHeight, charWidth, charHeight)));
                    charIndex++;
                }
            }
        }
示例#2
0
 /// <summary>
 /// Creates a new AnimatedSprite.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="spriteFrameName"></param>
 /// <param name="delay">Delay in milliseconds</param>
 public AnimatedSprite(Game game, string spriteFrameName, int delay, SpriteFrameCache spriteFrameCache = null)
     : base(game, spriteFrameName, 0, 0, spriteFrameCache)
 {
     this.isRepeatable        = true;
     this.completedAFullCycle = false;
     this.milliseconds        = 0;
     frames = new List <AnimationFrame>();
     if (!string.IsNullOrEmpty(spriteFrameName))
     {
         AddFrame(spriteFrameName, delay);
     }
     frameIndex = 0;
 }
        /// <summary>
        /// Creates a new sprite.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="spriteFrameName"></param>
        public Sprite(Game game, string spriteFrameName, int x = 0, int y = 0, SpriteFrameCache spriteFrameCache = null)
            : base(game)
        {
            this.spriteFrameCache = spriteFrameCache == null ? SosEngine.Core.SpriteFrameCache : spriteFrameCache;

            scaleX   = 1.0f;
            scaleY   = 1.0f;
            origin   = Vector2.Zero;
            Position = Vector2.Zero;
            if (!string.IsNullOrWhiteSpace(spriteFrameName))
            {
                spriteFrame = this.spriteFrameCache.GetSpriteFrame(spriteFrameName);
                Position    = new Vector2(x, y);
            }
        }
示例#4
0
        /// <summary>
        /// Init the game engine. This should be the first thing to call in
        /// the LoadContent method.
        /// </summary>
        /// <param name="_game"></param>
        public static void Init(Game _game, int _renderWith, int _renderHeight, bool _useScanlines)
        {
            game         = _game;
            RenderWidth  = _renderWith;
            RenderHeight = _renderHeight;

            UseScanlines             = _useScanlines;
            random                   = new Random(DateTime.Now.TimeOfDay.Milliseconds);
            input                    = new Input();
            soundEffectCache         = new List <SoundEffect>();
            texture2DCache           = new List <Texture2D>();
            shaderCache              = new List <Effect>();
            bitmapFontCache          = new List <BitmapFont>();
            SpriteBatch              = new SpriteBatch(game.GraphicsDevice);
            SceneManager             = new SceneManager(game);
            SaveDataManager          = new SaveDataManager();
            SosEngine.Core.ModPlayer = new SosEngine.ModPlayer();
            SpriteFrameCache         = new SpriteFrameCache();
            drawing2D                = new Drawing2D(game.GraphicsDevice);
            Mouse.WindowHandle       = game.Window.Handle;
            game.IsMouseVisible      = Debug;
            logHistory               = new List <string>();
        }