LibGDX FreeTypeFontGenerator

5

我使用最新的Gradle基础设置应用程序v1.1.0创建了LibGDX项目。

在创建时我没有添加FreeType扩展。

现在我需要它。如何将其添加到已创建的项目中?

2个回答

12

来自libGDX的Wiki

FreeTypeFont Gradle

核心依赖:

  • compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"

桌面依赖:

  • compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

安卓依赖:

  • compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
  • natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
  • natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
  • natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"

iOS依赖:

  • compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
  • natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"

别忘了刷新你的依赖哦 ;)


我已经在我的配置文件中添加了内容,但我仍然无法导入FreetypeFontGenerator。 - KiKo
1
你可能需要重新构建Gradle模型,或者如果这更有意义的话,“重新导入依赖项”。 - EpicPandaForce
1
@KiKo 我认为你可以像这样操作:右键单击项目 > "gradle" > "刷新依赖项" - NiziL
谢谢你,@Nizil,这就是我需要的 :) - KiKo
我猜这对Gradle来说更有意义。不过我还需要学习它使用的术语以及如何进行操作,呵呵。 - EpicPandaForce

9

以下是包含所有模块的完整 build.gradle 文件,您可以查看与 FreeType 相关的模块,并将其添加到您的 gradle 配置中。

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10+'
        classpath 'com.github.jtakakura:gradle-robovm-plugin:0.0.9'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = 'klaxon-game'
        gdxVersion = '1.1.0'
        roboVMVersion = '0.0.13'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.box2dlights:box2dlights:1.2"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers-android:$gdxVersion"
    }
}

project(":ios") {
    apply plugin: "java"
    apply plugin: "robovm"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "org.robovm:robovm-rt:${roboVMVersion}"
        compile "org.robovm:robovm-cocoatouch:${roboVMVersion}"
        compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
        natives "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-ios"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
    }
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
        compile "com.badlogicgames.box2dlights:box2dlights:1.2"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

请注意,自2014年6月12日以来,已添加了新的模块,例如Ashley(https://github.com/libgdx/ashley/wiki/How-to-use-Ashley)。 - EpicPandaForce

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接