Ashley过期/无法更新(Family.all()不存在)



我正试图让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;
        }
    }
}

这是建筑.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"
}

我得到的错误是"所有人都有私人访问权限"。auto-complete告诉我唯一可以访问的是Family类中的"getFor()"。到目前为止,引擎、实体等都能顺利工作。我运行JDK 7,既作为安装在我机器上的JDK,也作为Intellij中的兼容模式。

我从git自述中获取了所有代码,并按照说明确保Ashley是作为依赖项内置的,尽管我在第一次创建项目时也包含了它。

我尝试了不同版本的Ashley(我想),并尝试在Intellij中更改JDK兼容性,但到目前为止什么都没有。我完全被难住了,我很感激任何帮助。

编辑:最近,"all"函数被添加到了Family类中,所以我能推测的最好的情况是,尽管将Ashlety 1.3.2作为依赖项进行了推送,但在将构建器模式添加到Family类之前,它仍然使用旧版本的Ashley。问题似乎是Gradle没有使用最新版本的Ashley。这让我更接近了,但我仍然不知道如何修复它。我已经尽我所能按照说明进行了安装。

好吧,我在处理一些无关的事情时终于弄明白了。我注意到一个XML文件引用了Ashley 1.0.1,它是在将all()函数添加到Family类之前的WAY。我不知道这个XML文件是否导致了问题,但这提醒了我,在某个时候,我在文件>项目结构中看到了一个"依赖项"选项卡。

所以我去了那里,点击了"核心",当我看的时候,我注意到尽管我的build.gradle告诉我,这个项目仍然引用了Ashley 1.0.1或其他旧版本。所以我删除了那个过时版本的Ashley,点击Add按钮(alt+insert),点击Library,然后点击New Library,再点击From Maven。

从那里,你可以得到一个搜索栏的对话,只需输入"ashley",它就会给你一个使用gradle脚本下载的ashley版本的列表。1.3.2版是您正在寻找的版本(1.3.3给了我一个错误,考虑到文档建议1.3.2,我不想变通)。如果在搜索中点击OK后它没有显示,请确保将该版本号添加到build.gradle中并运行依赖关系构建。

在那之后,你只需点击OK,申请等,然后离开。从那里开始,Family.all()开始工作!Ashley更新了最新版本。希望这个答案能帮助其他人,尽管它只适用于Intellij(Eclipse似乎更受欢迎),因为我几乎竭尽全力想弄清楚它,但没有太多信息。

首先根据ashley的javaapi文档Family.all(PositionComponent.class,VelocityComponent.class).get()族不能直接实例化,但必须通过生成器访问(以Family.all)、Family.one()或Family.exclude()开头),这是为了避免描述相同组件的重复族。

来自GitHub的Ashleys Family Class源代码供您参考

最新更新