我试图使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"
}


我具体得到的错误是“所有人都有私有访问权限”。自动完成告诉我唯一可以访问的是Family类中的“ getFor()”。到目前为止,引擎,实体等一切正常。我既将JDK 7作为计算机上安装的JDK,又作为Intellij中的兼容模式运行。

我从git自述文件中获取了所有代码,并遵循了确保Ashley作为依赖项内置的说明,尽管在我第一次创建项目时也将其包括在内。

我尝试了不同版本的Ashley(我认为),并且尝试更改Intellij中的JDK兼容性,到目前为止什么也没有。我完全被困在这里,感谢您的帮助。

编辑:最近,“所有”功能已添加到Family类,所以我能推测的是,尽管将Ashlety 1.3.2推为依赖项,但在将构建器模式添加到Family之前,它仍使用Ashley的旧版本。类。问题似乎是Gradle没有使用Ashley的最新版本。这使我离得更近,但是我仍然不知道如何解决它。我已尽我所能按照安装说明进行操作。

最佳答案

好的,我在进行无关的工作时终于明白了。我注意到一个引用Ashley 1.0.1的XML文件,它是在将all()函数添加到Family类之前的。我不知道此XML文件是否引起了问题,但这使我想起,在某些时候,我已经看到在“文件”>“项目结构”中有一个“依赖项”选项卡。

所以我去了那里,然后单击“核心”,当我看时我注意到,尽管我的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似乎更受欢迎),因为我要扯掉头发试图找出答案,并且那里没有很多信息。

07-27 13:37