/// <summary> /// Parses string to a set of sprites from pre-defined textures. /// </summary> /// <param name="data"></param> /// <param name="textPosition"></param> /// <param name="symbolScale"></param> /// <returns></returns> public static SpriteBatch ParseStringToSprites(string data, Vector2 textPosition, Vector2 symbolScale) { if (data.Equals(string.Empty)) { throw new ArgumentException("There is no parse data into the input string."); } var sprites = new List <Sprite>(); var startPos = textPosition; // Create an offset with the space size of 5. var spaceWidth = -7; var offset = digitTextures[0].Width / 2 + spaceWidth; foreach (var @char in data) { Sprite symbolSprite; for (int i = 0; i < digits.Length; i++) { if (@char == digits[i]) { symbolSprite = new Sprite(digitTextures[i], startPos, symbolScale, textPosition, 10); sprites.Add(symbolSprite); // Make an offset by X-axis for the next symbol if there is one. textPosition += new Vector2(offset, 0); } } } var textOutputSprites = SpriteBatch.CreateSpriteBatch(sprites.ToArray()); return(textOutputSprites); }
/// <summary> /// Default ctor. /// </summary> public PurpleCar() { base.id = "Purple"; SetStartCarPosition(new Vector2(85f, 435f)); var vehicleTexture = ContentLoader.LoadTexture(@"Contents\Cars\purple.png"); var vehicleSprite = new Sprite(vehicleTexture, Position, new Vector2(0.4f, 0.4f), new Vector2(0f, 0f), 2); spriteRenderer.RenderQueue = SpriteBatch.CreateSpriteBatch(vehicleSprite); }
/// <summary> /// Default ctor with setting a position. /// </summary> /// <param name="uiTexturePath"></param> /// <param name="position"></param> public UIElement(string uiTexturePath, Vector2 position) { spriteRenderer = (SpriteRenderer)AddComponent("SpriteRenderer"); base.Position = position; var uiTex = ContentLoader.LoadTexture(uiTexturePath); var uiSprite = new Sprite(uiTex, Position, new Vector2(1f, 1f), new Vector2(0f, 0f), 10); spriteRenderer.RenderQueue = SpriteBatch.CreateSpriteBatch(uiSprite); }
/// <summary> /// Default ctor. /// </summary> /// <param name="backgroundPath"></param> public Environment(string backgroundPath) { spriteRenderer = (SpriteRenderer)AddComponent("SpriteRenderer"); base.Position = new Vector2(0f, 0f); var bgTexture = ContentLoader.LoadTexture(backgroundPath); var bgSprite = new Sprite(bgTexture, Position, new Vector2(1f, 1f), new Vector2(0f, 0f), -1); spriteRenderer.RenderQueue = SpriteBatch.CreateSpriteBatch(bgSprite); // Middle collider. base.collider = new PolyCollider(this, new Vector2(1310f, 480f)); // Add screen bounds. EngineCore.AddGameObject(new Bound(new Vector2(-945f, 0f), new Vector2(20f, 1080f))); EngineCore.AddGameObject(new Bound(new Vector2(945f, 0f), new Vector2(20f, 1080f))); EngineCore.AddGameObject(new Bound(new Vector2(0f, 525f), new Vector2(1920f, 20f))); EngineCore.AddGameObject(new Bound(new Vector2(0f, -525f), new Vector2(1920f, 20f))); }