美文网首页
第一章:Hello Libgdx

第一章:Hello Libgdx

作者: xiaolei123 | 来源:发表于2018-07-27 15:54 被阅读81次

    1.IDEA 新建 Gradle JAVA 项目

    创建项目
    1. Gradle配置
    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函数

    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

    相关文章

      网友评论

          本文标题:第一章:Hello Libgdx

          本文链接:https://www.haomeiwen.com/subject/sglgmftx.html