예제 #1
0
 public override void CreateUI(GLEx g, int x, int y, LComponent component,
                               LTexture[] buttonImage)
 {
     if (Touch.IsUp())
     {
         FreeClick();
     }
     if (pack != null)
     {
         pack.GLBegin();
         pack.Draw(0, x, y, backWidth, backHeight);
         if (isClick)
         {
             if (angle < 360)
             {
                 angle += 1;
             }
             else
             {
                 angle = 0;
             }
             pack.Draw(2, x + centerX, y + centerY, dotWidth, dotHeight,
                       angle, null);
         }
         pack.Draw(1, x + (backWidth - baseWidth) * 0.5f, y
                   + (backHeight - baseHeight) * 0.5f, baseWidth, baseHeight);
         pack.GLEnd();
     }
     else
     {
         batch.Begin();
         batch.Draw(back, x, y, backWidth, backHeight);
         if (isClick)
         {
             if (angle < 360)
             {
                 angle += 1;
             }
             else
             {
                 angle = 1;
             }
             batch.Draw(dot, x + centerX, y + centerY, dotWidth, dotHeight,
                        angle);
         }
         batch.Draw(fore, (x + (backWidth - baseWidth) * 0.5f),
                    (y + (backHeight - baseHeight) * 0.5f), baseWidth,
                    baseHeight);
         batch.End();
     }
 }
예제 #2
0
        public void Draw(GLEx g, SpriteBatch batch, float offsetX, float offsetY)
        {
            bool useBatch = (batch != null);

            if (!dirty && lastOffsetX == offsetX && lastOffsetY == offsetY)
            {
                imgPack.GLCache();
                if (playAnimation)
                {
                    int[][] maps = field.GetMap();
                    for (int i = firstTileX; i < lastTileX; i++)
                    {
                        for (int j = firstTileY; j < lastTileY; j++)
                        {
                            if (i > -1 && j > -1 && i < field.width &&
                                j < field.height)
                            {
                                int id = maps[j][i];
                                foreach (Tile tile  in  arrays)
                                {
                                    if (tile.isAnimation && tile.id == id)
                                    {
                                        if (useBatch)
                                        {
                                            batch.Draw(
                                                tile.animation.GetSpriteImage(),
                                                field.TilesToWidthPixels(i)
                                                + offsetX,
                                                field.TilesToHeightPixels(j)
                                                + offsetY,
                                                field.GetTileWidth(),
                                                field.GetTileHeight());
                                        }
                                        else
                                        {
                                            g.DrawTexture(
                                                tile.animation.GetSpriteImage(),
                                                field.TilesToWidthPixels(i)
                                                + offsetX,
                                                field.TilesToHeightPixels(j)
                                                + offsetY,
                                                field.GetTileWidth(),
                                                field.GetTileHeight());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (arrays.Count == 0)
                {
                    throw new Exception("Not to add any tiles !");
                }
                imgPack.GLBegin();
                firstTileX = field.PixelsToTilesWidth(-offsetX);
                firstTileY = field.PixelsToTilesHeight(-offsetY);
                lastTileX  = firstTileX + field.PixelsToTilesWidth(maxWidth) + 1;
                lastTileX  = MathUtils.Min(lastTileX, field.width);
                lastTileY  = firstTileY + field.PixelsToTilesHeight(maxHeight) + 1;
                lastTileY  = MathUtils.Min(lastTileY, field.height);
                int[][] maps = field.GetMap();
                for (int i = firstTileX; i < lastTileX; i++)
                {
                    for (int j = firstTileY; j < lastTileY; j++)
                    {
                        if (i > -1 && j > -1 && i < field.width && j < field.height)
                        {
                            int id = maps[j][i];
                            foreach (Tile tile  in  arrays)
                            {
                                if (playAnimation)
                                {
                                    if (tile.id == id)
                                    {
                                        if (tile.isAnimation)
                                        {
                                            if (useBatch)
                                            {
                                                batch.Draw(
                                                    tile.animation
                                                    .GetSpriteImage(),
                                                    field.TilesToWidthPixels(i)
                                                    + offsetX,
                                                    field.TilesToHeightPixels(j)
                                                    + offsetY, field
                                                    .GetTileWidth(),
                                                    field.GetTileHeight());
                                            }
                                            else
                                            {
                                                g.DrawTexture(
                                                    tile.animation
                                                    .GetSpriteImage(),
                                                    field.TilesToWidthPixels(i)
                                                    + offsetX,
                                                    field.TilesToHeightPixels(j)
                                                    + offsetY, field
                                                    .GetTileWidth(),
                                                    field.GetTileHeight());
                                            }
                                        }
                                        else
                                        {
                                            imgPack.Draw(tile.imgId,
                                                         field.TilesToWidthPixels(i)
                                                         + offsetX,
                                                         field.TilesToHeightPixels(j)
                                                         + offsetY,
                                                         field.GetTileWidth(),
                                                         field.GetTileHeight());
                                        }
                                    }
                                }
                                else if (tile.id == id)
                                {
                                    imgPack.Draw(tile.imgId,
                                                 field.TilesToWidthPixels(i) + offsetX,
                                                 field.TilesToHeightPixels(j) + offsetY,
                                                 field.GetTileWidth(),
                                                 field.GetTileHeight());
                                }
                            }
                        }
                    }
                }
                imgPack.GLEnd();
                lastOffsetX = offsetX;
                lastOffsetY = offsetY;
                dirty       = false;
            }
            if (listener != null)
            {
                listener.Draw(g, offsetX, offsetY);
            }
        }