Ashley 已过时/无法更新(Family.all() 不存在)
Ashley Outdated / Cannot Be Updated (Family.all() does not exist)
我正在努力让 Ashley 起来 运行,但我 运行 遇到了问题。我尝试调用 Family.all(),但 IntelliJ IDEA 14 向我保证无法访问此函数。这是我正在尝试 运行 的系统:
package com.mygdx.game.Systems;
import com.badlogic.ashley.core.*;
import com.badlogic.ashley.utils.ImmutableArray;
import com.mygdx.game.Components.PositionComponent;
import com.mygdx.game.Components.VelocityComponent;
import javax.management.ImmutableDescriptor;
public class MovementSystem extends EntitySystem {
private ImmutableArray<Entity> entities;
private ComponentMapper<PositionComponent> pm = ComponentMapper.getFor(PositionComponent.class);
private ComponentMapper<VelocityComponent> vm = ComponentMapper.getFor(VelocityComponent.class);
public MovementSystem() {}
public void addedToEngine(Engine engine) {
entities = engine.getEntitiesFor(Family.all(PositionComponent.class, VelocityComponent.class).get());
}
public void update(float deltaTime) {
for (int i = 0; i < entities.size(); ++i) {
Entity entity = entities.get(i);
PositionComponent position = pm.get(entity);
VelocityComponent velocity = vm.get(entity);
position.x += velocity.x * deltaTime;
position.y += velocity.y * deltaTime;
}
}
}
这里是 build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'SomeApp'
gdxVersion = '1.4.1'
roboVMVersion = '1.0.0-alpha-04'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.2'
aiVersion = '1.4.0'
}
repositories {
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-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
我得到的具体错误是"all has private access"。自动完成功能告诉我唯一可以访问的是来自家庭 class 的 "getFor()"。到目前为止,引擎、实体等都可以正常工作。我正在 运行ning JDK 7 作为安装在我机器上的 JDK 和 Intellij 中的兼容模式。
我从 git 自述文件中获取了所有代码,并按照说明确保 Ashley 作为依赖项内置,尽管我在首次创建项目时也包含了它。
我尝试了不同版本的 Ashley(我认为),并且我尝试更改 Intellij 中的 JDK 兼容性,但到目前为止什么都没有。我在这里完全被难住了,感谢任何帮助。
编辑:最近 "all" 功能被添加到家族 class,所以我能推测的最好的是尽管将 Ashlety 1.3.2 作为依赖项推送,但它仍在使用旧版本在将构建器模式添加到 Family 之前的 Ashley class。问题似乎是 Gradle 没有使用最新版本的 Ashley。这让我更接近,但我仍然无法弄清楚如何解决它。我已尽可能按照说明进行安装。
首先根据 ashley's java api doc
Family.all(PositionComponent.class, VelocityComponent.class).get() 族不能直接实例化,必须通过构建器访问(以[开头=18=]()、Family.one() 或 Family.exclude()),这是为了避免描述相同组件的重复系列。
Ashleys Family Class Source Code from the GitHub for your reference
好吧,我在做一些不相关的事情时终于想通了。我注意到一个 XML 文件引用了 Ashley 1.0.1,这是在将 all() 函数添加到家族 class 之前的方式。我不知道这个 XML 文件是否导致了问题,但这让我想起了我在某个时候看到的,在文件>项目结构中有一个 "Dependencies" 选项卡。
所以我去了那里,点击了 "core",当我看的时候我注意到尽管我的 build.gradle 告诉我的是什么,该项目仍然引用 Ashley 1.0.1 或其他一些旧版本。所以我删除了 Ashley 的过时版本,点击添加按钮 (alt+insert),点击库,然后点击新建库,然后点击来自 Maven。
从那里,您会看到与搜索栏的对话,只需输入 "ashley",它就会为您提供您使用 gradle 脚本访问的 Ashley 版本列表下载。版本 1.3.2 是您正在寻找的版本(1.3.3 给了我一个错误,考虑到文档推荐 1.3.2,我不想解决这个问题)。如果在搜索中点击确定后它没有出现,请确保将该版本号添加到 build.gradle 和 运行 依赖项构建中。
之后,您只需点击“确定”、“申请”等即可退出。从那里开始,Family.all() 起作用了!并且 Ashley 已更新到最新版本。希望这个答案能对其他人有所帮助,即使它只适用于 Intellij(而且 Eclipse 似乎更受欢迎),因为我想弄清楚我的头发,但那里没有太多信息。
我正在努力让 Ashley 起来 运行,但我 运行 遇到了问题。我尝试调用 Family.all(),但 IntelliJ IDEA 14 向我保证无法访问此函数。这是我正在尝试 运行 的系统:
package com.mygdx.game.Systems;
import com.badlogic.ashley.core.*;
import com.badlogic.ashley.utils.ImmutableArray;
import com.mygdx.game.Components.PositionComponent;
import com.mygdx.game.Components.VelocityComponent;
import javax.management.ImmutableDescriptor;
public class MovementSystem extends EntitySystem {
private ImmutableArray<Entity> entities;
private ComponentMapper<PositionComponent> pm = ComponentMapper.getFor(PositionComponent.class);
private ComponentMapper<VelocityComponent> vm = ComponentMapper.getFor(VelocityComponent.class);
public MovementSystem() {}
public void addedToEngine(Engine engine) {
entities = engine.getEntitiesFor(Family.all(PositionComponent.class, VelocityComponent.class).get());
}
public void update(float deltaTime) {
for (int i = 0; i < entities.size(); ++i) {
Entity entity = entities.get(i);
PositionComponent position = pm.get(entity);
VelocityComponent velocity = vm.get(entity);
position.x += velocity.x * deltaTime;
position.y += velocity.y * deltaTime;
}
}
}
这里是 build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'SomeApp'
gdxVersion = '1.4.1'
roboVMVersion = '1.0.0-alpha-04'
box2DLightsVersion = '1.3'
ashleyVersion = '1.3.2'
aiVersion = '1.4.0'
}
repositories {
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-controllers-desktop:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
我得到的具体错误是"all has private access"。自动完成功能告诉我唯一可以访问的是来自家庭 class 的 "getFor()"。到目前为止,引擎、实体等都可以正常工作。我正在 运行ning JDK 7 作为安装在我机器上的 JDK 和 Intellij 中的兼容模式。
我从 git 自述文件中获取了所有代码,并按照说明确保 Ashley 作为依赖项内置,尽管我在首次创建项目时也包含了它。
我尝试了不同版本的 Ashley(我认为),并且我尝试更改 Intellij 中的 JDK 兼容性,但到目前为止什么都没有。我在这里完全被难住了,感谢任何帮助。
编辑:最近 "all" 功能被添加到家族 class,所以我能推测的最好的是尽管将 Ashlety 1.3.2 作为依赖项推送,但它仍在使用旧版本在将构建器模式添加到 Family 之前的 Ashley class。问题似乎是 Gradle 没有使用最新版本的 Ashley。这让我更接近,但我仍然无法弄清楚如何解决它。我已尽可能按照说明进行安装。
首先根据 ashley's java api doc Family.all(PositionComponent.class, VelocityComponent.class).get() 族不能直接实例化,必须通过构建器访问(以[开头=18=]()、Family.one() 或 Family.exclude()),这是为了避免描述相同组件的重复系列。
Ashleys Family Class Source Code from the GitHub for your reference
好吧,我在做一些不相关的事情时终于想通了。我注意到一个 XML 文件引用了 Ashley 1.0.1,这是在将 all() 函数添加到家族 class 之前的方式。我不知道这个 XML 文件是否导致了问题,但这让我想起了我在某个时候看到的,在文件>项目结构中有一个 "Dependencies" 选项卡。
所以我去了那里,点击了 "core",当我看的时候我注意到尽管我的 build.gradle 告诉我的是什么,该项目仍然引用 Ashley 1.0.1 或其他一些旧版本。所以我删除了 Ashley 的过时版本,点击添加按钮 (alt+insert),点击库,然后点击新建库,然后点击来自 Maven。
从那里,您会看到与搜索栏的对话,只需输入 "ashley",它就会为您提供您使用 gradle 脚本访问的 Ashley 版本列表下载。版本 1.3.2 是您正在寻找的版本(1.3.3 给了我一个错误,考虑到文档推荐 1.3.2,我不想解决这个问题)。如果在搜索中点击确定后它没有出现,请确保将该版本号添加到 build.gradle 和 运行 依赖项构建中。
之后,您只需点击“确定”、“申请”等即可退出。从那里开始,Family.all() 起作用了!并且 Ashley 已更新到最新版本。希望这个答案能对其他人有所帮助,即使它只适用于 Intellij(而且 Eclipse 似乎更受欢迎),因为我想弄清楚我的头发,但那里没有太多信息。