-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


LibGDX + Scene2d ( Kotlin). 0

, 02 2017 . 23:46 +
! , ! , . ? , , . . . Scene2d ! - . . , , . , . . .

. . Google Docs docs.google.com/document/d/1m_A_Pupfk7gub732ZkGLuIYY0ezSCmSxqQffO93uXpY/edit?usp=sharing



  1. habrahabr.ru (, , )
  2. , (, , ; , , )
  3. (, )
  4. Google Play (, , )


. . . . , ( ).


/





, , .

. /. , .




, , Adobe Experience Design CC (Beta). , www.adobe.com/ru/products/experience-design.html . , , . , . Adobe Experience Design drive.google.com/file/d/0B2CQZfruKhbWcG5EOWZYenN6UUU/view?usp=sharing
, . , . .

? : ptsiber@bitbucket.org/terrav/medieval-tycoon.git

Android Studio 3.0 ( Canary 5), Android SKD LibGDX libgdx.badlogicgames.com/nightlies/dist/gdx-setup.jar
, . .

LibGDX :
java -jar gdx-setup.jar


, LibGDX , PC, Android, iOS HTML ( GWT, Kotlin, HTML ). :

Freetype ttf/otf
Tools


. , . LibGDX , PC / Android . 2-3 .


  • DesktopLauncher
  • Kotlin
  • Kotlin not configured
  • gradle kotlin-desktop
  • desktop
  • Scene2D. ,


DesktopLauncher




, DesktopLauncher android/assets. DesktopLauncher
initial commit after libgdx wizard


, android. .

Kotlin


LibGDX gradle. build.gradle build.gradle core, android desktop. core. android AdMob + immersive mode + Google Play .

java kotlin apply plugin: java apply plugin: kotlin. android/build.gradle apply plugin: 'kotlin-android'. build.gradle
build.gradle
         mavenCentral()
         maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
         jcenter()
+
+        maven { url 'https://maven.google.com' }
     }
+
+    ext.kotlin_version = '1.1.3'
+
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.2.0'
-        
-
+        // uncomment for desktop version
+        // classpath 'com.android.tools.build:gradle:2.3.2'
+        classpath 'com.android.tools.build:gradle:3.0.0-alpha5'
+        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
     }
 }
 
@@ -37,7 +43,7 @@
 }
 
 project(":desktop") {
-    apply plugin: "java"
+    apply plugin: "kotlin"
 
 
     dependencies {
@@ -74,13 +80,13 @@
 }
 
 project(":core") {
-    apply plugin: "java"
+    apply plugin: "kotlin"
 
 
     dependencies {
         compile "com.badlogicgames.gdx:gdx:$gdxVersion"
         compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
-        
+        compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
     }
 }



, buildscript.dependencies kotlin-gradle-plugin core compile- kotlin-stdlib ( kotlin-stdlib-jre8).

android, desktop - Android Studio 3.0 Canary 5. gradle desktop-run ( Android device/emulator android:run). Android Studio
Exception in thread main java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
DesktopLauncher'a gradle !

java kt / Ctrl+Alt+Shitf+K. Kotlin'a
java
public class MedievalTycoonGame extends ApplicationAdapter {
	SpriteBatch batch;
	Texture img;
	
	@Override
	public void create () {
		batch = new SpriteBatch();
		img = new Texture("badlogic.jpg");
	}

	@Override
	public void render () {
		Gdx.gl.glClearColor(1, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.begin();
		batch.draw(img, 0, 0);
		batch.end();
	}
	
	@Override
	public void dispose () {
		batch.dispose();
		img.dispose();
	}
}



kotlin
class MedievalTycoonGame : ApplicationAdapter() {
    internal var batch: SpriteBatch //   <-    private lateinit var batch: SpriteBatch
    internal var img: Texture //   <-    private lateinit var img: Texture
    override fun create() {
        batch = SpriteBatch()
        img = Texture("badlogic.jpg")
    }

    override fun render() {
        Gdx.gl.glClearColor(1f, 0f, 0f, 1f)
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
        batch.begin()
        batch.draw(img, 0f, 0f)
        batch.end()
    }

    override fun dispose() {
        batch.dispose()
        img.dispose()
    }
}


internal = package java. ( ). , nullable ( - null-safety). kotlin lateinit, , , null. . , ,
private val batch = SpriteBatch()
private val img = Texture("badlogic.jpg")


Kotlin not configured


Android Studio. gradle


gradle kotlin-desktop


, desktop , . build.gradle
classpath 'com.android.tools.build:gradle:2.3.2'
gradle-wrapper.properties gradle-3.3-all.zip

desktop


DesktopLauncher . . vSync .. , desktop config.foregroundFPS=60 ( ), 100%.
        config.width = 576
        config.height = 1024
        config.resizable = false
        config.vSyncEnabled = false


Scene2D. ,


Scene2D. .

Scene2D () UI. , , (, , ..). . . , .

, . , , , ( Actor'). top/center/left/width .. . hello world , . . , , z-index .. , . :

class MedievalTycoonGame : Game() {

    val viewport: FitViewport = FitViewport(AppConstants.APP_WIDTH, AppConstants.APP_HEIGHT)

    override fun create() {
        screen = LoadingScreen(viewport)
    }
}

MedievalTycoonGame Game, Screen. , LoadingScreen LoadingStage. .. , LoadingScreen.kt

LoadingScreen.kt
class LoadingScreen(val viewport: Viewport) : ScreenAdapter() {

    private val loadingStage = LoadingStage(viewport)

    override fun render(delta: Float) {
        Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)

        loadingStage.act()
        loadingStage.draw()
    }

    override fun resize(width: Int, height: Int) {
        viewport.update(width, height)
    }
}

class LoadingStage(viewport: Viewport) : Stage(viewport) {

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


LoadingScreen act() draw() LoadingStage. act() , . Draw() .

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


    public LoadingStage() {
        Image backgroundImage = new Image(new Texture("backgrounds/loading-logo.png"));
        backgroundImage.setFillParent(true);
        backgroundImage.setScaling(Scaling.fill);
        addActor(backgroundImage);
    }


kotlin . apply. kotlin . java . . 3+ , ( ) java .

. , Scene2D . ;) ( ), Scene2D - . . 90% . ?


  • Scene2D


P.S. aka Vitaly S Alexius
www.rom.ac
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/332144/

:  

: [1] []
 

:
: 

: ( )

:

  URL