registerEntityLoader andengine2.0中的未定义错误锚定中心,andengine GLS2.0

时间:2015-10-11 12:25:54

标签: android andengine

我的游戏中有负载水平。但它显示了一些错误 registerEntityLoader和Loadlevelfromasset"。我认为库文件中缺少它。我使用Andengines 2.0和锚点中心作为库。

但显示这样的错误 方法registerEntityLoader(new EntityLoader(){})未定义类型SimpleLevelLoader

对于SimpleLevelLoader类型,未定义方法loadLevelFromAsset(AssetManager,String)

我的代码是

private void loadLevel(int levelID)
{
    final SimpleLevelLoader levelLoader = new SimpleLevelLoader(vbom);

    final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0.01f, 0.5f);

    levelLoader.registerEntityLoader(new EntityLoader<SimpleLevelEntityLoaderData>(LevelConstants.TAG_LEVEL)
    {
        public IEntity onLoadEntity(final String pEntityName, final IEntity pParent, final Attributes pAttributes, final SimpleLevelEntityLoaderData pSimpleLevelEntityLoaderData) throws IOException 
        {
            final int width = SAXUtils.getIntAttributeOrThrow(pAttributes, LevelConstants.TAG_LEVEL_ATTRIBUTE_WIDTH);
            final int height = SAXUtils.getIntAttributeOrThrow(pAttributes, LevelConstants.TAG_LEVEL_ATTRIBUTE_HEIGHT);

            // TODO later we will specify camera BOUNDS and create invisible walls
            // on the beginning and on the end of the level.

            return GameScene.this;
        }
    });

    levelLoader.registerEntityLoader(new EntityLoader<SimpleLevelEntityLoaderData>(TAG_ENTITY)
    {
        public IEntity onLoadEntity(final String pEntityName, final IEntity pParent, final Attributes pAttributes, final SimpleLevelEntityLoaderData pSimpleLevelEntityLoaderData) throws IOException
        {
            final int x = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_X);
            final int y = SAXUtils.getIntAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_Y);
            final String type = SAXUtils.getAttributeOrThrow(pAttributes, TAG_ENTITY_ATTRIBUTE_TYPE);

            final Sprite levelObject;

            if (type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_PLATFORM1))
            {
                levelObject = new Sprite(x, y, resourcesManager.platform1_region, vbom);
                PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF).setUserData("platform1");
            } 
            else if (type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_PLATFORM2))
            {
                levelObject = new Sprite(x, y, resourcesManager.platform2_region, vbom);
                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
                body.setUserData("platform2");
                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
            }
            else if (type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_PLATFORM3))
            {
                levelObject = new Sprite(x, y, resourcesManager.platform3_region, vbom);
                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
                body.setUserData("platform3");
                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
            }
            else if (type.equals(TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_COIN))
            {
                levelObject = new Sprite(x, y, resourcesManager.coin_region, vbom)
                {
                    @Override
                    protected void onManagedUpdate(float pSecondsElapsed) 
                    {
                        super.onManagedUpdate(pSecondsElapsed);

                        /** 
                         * TODO
                         * we will later check if player collide with this (coin)
                         * and if it does, we will increase score and hide coin
                         * it will be completed in next articles (after creating player code)
                         */
                    }
                };
                levelObject.registerEntityModifier(new LoopEntityModifier(new ScaleModifier(1, 1, 1.3f)));
            }            
            else
            {
                throw new IllegalArgumentException();
            }

            levelObject.setCullingEnabled(true);

            return levelObject;
        }
    });

    levelLoader.loadLevelFromAsset(activity.getAssets(), "level/" + levelID + ".lvl");
}

我使用了最新版本的Anchor。帮帮我解决......

0 个答案:

没有答案