第一章:Hello Libgdx

2018-08-10 11:36:21 浏览数 (1)

1.IDEA 新建 Gradle JAVA 项目

创建项目

  1. Gradle配置
代码语言:javascript复制
repositories {
    mavenCentral()
    maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
ext {
    gdxVersion = '0.9.9'
    runPlatform = "natives-desktop"
}
dependencies {
    compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
    // compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:$runPlatform"
    compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:$runPlatform"
   //  compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:$runPlatform"
}

3.Main函数

代码语言:javascript复制
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL10

fun main(args: Array<String>)
{
    val config = LwjglApplicationConfiguration()
    config.width = 480
    config.height = 320
    config.useGL20 = true
    config.backgroundFPS = 30
    config.foregroundFPS = 120
    config.initialBackgroundColor = Color.GRAY
    config.resizable = false
    config.title = "Hello LibGdx"
    LwjglApplication(MainPage(), config)
}

class MainPage : ApplicationAdapter()
{
    override fun render()
    {
        Gdx.gl.glClearColor(1F, 1F, 1F, 1F)
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)
    }
}

4.效果

运行界面

5.代码链接

https://gitee.com/xcode_xiao/LibGdxDemos2/tree/master/HelloGDX

0 人点赞