Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java ME (J2ME) > TiledLayer - рисует ли он за экраном?


Автор: 604 17.11.2006, 13:17
Привет!
Возник такой вопрос! Если я создаю TiledLayer размером больше экрана телефона, то рисует ли он за пределами экрана?

Автор: W0LF 17.11.2006, 14:44
Че-то не совсем вопрос понял... Как это - рисует за пределами экрана?

Автор: 604 17.11.2006, 14:54
Всмысле имеется в виду... вот если например создаем new TiledLayer(15, 15, image, 20, 20), размер этого слоя получается больше размера физического экрана. Так вот потом при отрисовке этого слоя LayerManаger рисует этот слой целиком или только ту часть которая видна на экране?

Автор: $tatic 23.11.2006, 19:35
Согласно документации:
Цитата

Rendering a TiledLayer
A TiledLayer can be rendered by manually calling its paint method; it can also be rendered automatically using a LayerManager object. 
The paint method will attempt to render the entire TiledLayer subject to the clip region of the Graphics object; the upper left corner of the TiledLayer is rendered at its current (x,y) position relative to the Graphics object's origin. The rendered region may be controlled by setting the clip region of the Graphics object accordingly.

Смотрим кусок декомпилированного кода класса:
Код

    public final void paint(Graphics g)
    {
        if(g == null)
            throw new NullPointerException();
        if(visible)
        {
            int tileIndex = 0;
            if(updated)
            {
                int arrayLength = 0;
                for(int row = 0; row < cellMatrix.length; row++)
                {
                    int totalCols = cellMatrix[row].length;
                    for(int column = 0; column < totalCols; column++)
                    {
                        tileIndex = cellMatrix[row][column];
                        if(tileIndex != 0)
                            arrayLength++;
                    }

                }

                if(x_src == null || arrayLength > x_src.length)
                {
                    x_src = new int[arrayLength];
                    y_src = new int[arrayLength];
                    x_dest = new int[arrayLength];
                    y_dest = new int[arrayLength];
                }
                tileArrayLength = arrayLength;
                updated = false;
            }
            int ty = y;
            int arrayIndex = 0;
            for(int row = 0; row < cellMatrix.length;)
            {
                int tx = x;
                int totalCols = cellMatrix[row].length;
                for(int column = 0; column < totalCols;)
                {
                    tileIndex = cellMatrix[row][column];
                    if(tileIndex != 0)
                    {
                        if(tileIndex < 0)
                            tileIndex = getAnimatedTile(tileIndex);
                        x_src[arrayIndex] = tileSetX[tileIndex];
                        y_src[arrayIndex] = tileSetY[tileIndex];
                        x_dest[arrayIndex] = tx;
                        y_dest[arrayIndex] = ty;
                        arrayIndex++;
                    }
                    column++;
                    tx += cellWidth;
                }

                row++;
                ty += cellHeight;
            }

            drawTiledRegion(g, sourceImage, tileArrayLength, x_src, y_src, cellWidth, cellHeight, 0, x_dest, y_dest, 20);
        }
    }

    private native void drawTiledRegion(Graphics g, Image image, int i, int ai[], int ai1[], int j, int k, 
            int l, int ai2[], int ai3[], int i1);

Автор: 604 23.11.2006, 21:39
Ээээ может я что то не понимаю? но судя по коду обходятся все клетки?!

Автор: $tatic 24.11.2006, 16:50
Да, ты прав, он все клетки рисует. Конечно от этого производительность падает. Но если хочешь, то можешь создать свой класс, наследованный от TiledLayer и переопределить в нем paint так, чтобы он вначале проверял видимость тайла, а потом только его прорисовывал.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)