public Tutorial(Vec2 position, Level level) : base() { canvas = new Canvas(500, 400); canvas.SetXY(position.x, position.y); image = new Sprite("tutorial_background.png"); image.SetScaleXY(0.4f); image.SetXY(canvas.x, canvas.y); isVisible = true; skip = new Button(new Vec2(canvas.x + 50, canvas.y + canvas.height - 50), 100, 50, "SKIP"); next = new Button(new Vec2(canvas.x + canvas.width - 200, canvas.y + canvas.height - 50), 100, 500, "NEXT"); count = 0; font = new Font("MV Boli", 18); AddChild(image); AddChild(canvas); AddChild(skip); AddChild(next); this.level = level; }
/// <summary> /// Draw a layer by index /// </summary> /// <param name="layerIndex"></param> public void DrawLayer(int layerIndex, GameObject parent) { int tileWidth = _mapData.TileWidth; int tileHeight = _mapData.TileHeight; int tileOrigin = _mapData.Layers[layerIndex].GetIntProperty("tileorigin", 0); // To draw mapData layer with opacity float[][] matrixItems = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new float[] { 0, 0, 0, _mapData.Layers[layerIndex].Opacity, 0 }, new float[] { 0, 0, 0, 0, 1 } }; ColorMatrix colorMatrix = new ColorMatrix(matrixItems); // Create an ImageAttributes object and set its color matrix. ImageAttributes imageAtt = new ImageAttributes(); imageAtt.SetColorMatrix( colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); //go through data and get the absolute ID, than with the absolute ID get the correspondent rectangle in tileset image int rows = _tileArrays[layerIndex].GetLength(0); int columns = _tileArrays[layerIndex].GetLength(1); for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { int tileIndex = _tileArrays[layerIndex][i, j] - 1; if (tileIndex < 0) { continue; } var spriteData = _tileSetSpritesData[tileIndex]; var sourceRect = spriteData.rect; var pt = new Point(i * _mapData.TileHeight, j * _mapData.TileWidth - tileOrigin); var canvas = new Canvas(_mapData.TileWidth, _mapData.TileHeight, false); canvas.graphics.DrawImage(_tileSetImages[spriteData.tileSetId], new Rectangle(0, 0, tileWidth, tileHeight), // destination rectangle sourceRect.X, // source rectangle x sourceRect.Y, // source rectangle y tileWidth, // source rectangle width tileHeight, // source rectangle height GraphicsUnit.Pixel, imageAtt); parent.AddChild(canvas); canvas.SetXY(pt.X, pt.Y); } } }