-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


LibGDX + Scene2d ( Kotlin). 1

, 07 2017 . 14:50 +
. , . , . , .

. LibGDX OpenGL. . . Drawable.

Drawable


Drawable, , Scene2d . , , , , .. Drawable . , . Drawable. TextureRegionDrawable, TiledDrawable NinePatchDrawable. :


Drawable


TextureRegionDrawable. . TiledDrawable. , . , 9-Box 9-Patch. ?

9-Patch


9-Patch , . , , .. 2 .

Table Layout


, ( Actor). Widget WidgetGroup. Widget , . WidgetGroup . , WidgetGroup . Scene2d . LibGDX WidgetGroup, Table. , . .



Kotlin
class TableStage : Stage() {

    init {

        val stageLayout = Table()
        addActor(stageLayout.apply {
            debugAll()
            setFillParent(true)

            pad(AppConstants.PADDING)
            defaults().expand().space(AppConstants.PADDING)

            row().let {
                add(Image(uiSkin.getDrawable("sample")))
                add(Image(uiSkin.getDrawable("sample"))).top().right()
                add(Image(uiSkin.getDrawable("sample"))).fill()
            }

            row().let {
                add(Image(uiSkin.getTiledDrawable("sample"))).fillY().left().colspan(2)
                add(Image(uiSkin.getTiledDrawable("sample"))).width(64f).height(64f).right().bottom()
            }

            row().let {
                add(Image(uiSkin.getDrawable("sample")))
                add(Image(uiSkin.getTiledDrawable("sample"))).fill().pad(AppConstants.PADDING)
                add(Image(uiSkin.getDrawable("sample"))).width(64f).height(64f)
            }
        })
    }
}


/ . . .

:

        ... 
        val stageLayout = Table()
        addActor(stageLayout.apply { //    
            debugAll() //      
            setFillParent(true) //      

            pad(AppConstants.PADDING)
            defaults().expand().space(AppConstants.PADDING)

            row().let {
                add(Image(uiSkin.getDrawable("sample")))
                add(Image(uiSkin.getDrawable("sample"))).top().right()
                add(Image(uiSkin.getDrawable("sample"))).fill()
            }

, .apply , apply . setFillParent(true) . , .

: setFillParent(true)

java

        ... 
        Table stageLayout = new Table();
        stageLayout.debugAll();
        stageLayout.setFillParent(true);

        stageLayout.pad(AppConstants.PADDING);
        stageLayout.defaults().expand().space(AppConstants.PADDING);

        stageLayout.row();
        stageLayout.add(Image(uiSkin.getDrawable("sample")));
        stageLayout.add(Image(uiSkin.getDrawable("sample"))).top().right();
        stageLayout.add(Image(uiSkin.getDrawable("sample"))).fill();

        addActor(stageLayout);

. , .. Widget/WidgetGroup.

Kotlin'e row() .let, . null check. let it -.

var name: String? = ...
name?.let { 
    if (it == "Alex") ...
}




add . Cell
row row. default Cell . , default Cell .

expand/expandX/expandY . ( ).

width/height .

.width(40f)
.width(Value.percentWidth(.4f, stageLayout)

fill/fillX/fillY

left/right/top/bottom ,

:




expand/expandX/expandY ( )
fill/fillX/fillY ( )
/ ( /)

Container<> Layout


Widget. Drawable background. header footer ( / ).

val stageLayout = Table()
addActor(stageLayout.apply {
...
    row().let {
        val headerContainer = Container()
        add(headerContainer.apply {
            background = TextureRegionDrawable(TextureRegion(Texture("images/status-bar-background.png")))
            //        
        }).height(100f).expandX()
    }

val stageLayout = Table()
addActor(stageLayout.apply {
    setFillParent(true)

    defaults().fill()

    row().let {
        val headerContainer = Container()
        add(headerContainer.apply {
            background = TextureRegionDrawable(TextureRegion(Texture("images/status-bar-background.png")))
        }).height(100f).expandX()
    }

    row().let {
        add(Image(Texture("backgrounds/main-screen-background.png")).apply {
            setScaling(Scaling.fill)
        }).expand()
    }

    row().let {
        val footerContainer = Container()
        add(footerContainer.apply {
            background = TextureRegionDrawable(TextureRegion(Texture("images/status-bar-background.png")))
            fill()

            actor = CommandPanel()
        }).height(160f).expandX()
    }
})


Loading Screen


:



:

val stageLayout = Table()
addActor(stageLayout.apply {
    setFillParent(true)
    background = TextureRegionDrawable(TextureRegion(Texture("backgrounds/loading-logo.png")))
})

. . , . ?

val stageLayout = Table()
val backgroundImage = Image(Texture("backgrounds/loading-logo.png"))
addActor(backgroundImage.apply {
    setFillParent(true)
    setScaling(Scaling.fill)
})

. , . . Scaling.fit. , (letterbox).

, , Progress Bar - 20% 60% . actor' . :



init {
    val backgroundImage = Image(Texture("backgrounds/loading-logo.png"))
    addActor(backgroundImage.apply {
        setFillParent(true)
        setScaling(Scaling.fill)
    })

    val stageLayout = Table()
    addActor(stageLayout.apply {
        setFillParent(true)

        row().let {
            add().width(Value.percentWidth(.6f, stageLayout)).height(Value.percentHeight(.8f, stageLayout))
        }

        row().let {
            add(progressBar).height(40f).fill() //  progressBar    
        }
    })
}


. / .

P.S. 4 . . . .

1

Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/332298/

:  

: [1] []
 

:
: 

: ( )

:

  URL