androidandenginetiledtmx

TMXLoader error when using Android Studio with AndEngineTMXTileExtension


I am trying to create a tower defense like game. I have created a tiled isometric map with Tiled Map Editor and have saved it is the assets folder in android studio. I am currently using andengine to load the map in my activity.

My MainActivity.Java :

package com.example.neelpatel104.towerfinisher;


import org.andengine.engine.Engine;
import org.andengine.engine.LimitedFPSEngine;
import org.andengine.engine.camera.BoundCamera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.util.FPSLogger;
import org.andengine.extension.tmx.TMXLayer;
import org.andengine.extension.tmx.TMXLoader;
import org.andengine.extension.tmx.TMXProperties;
import org.andengine.extension.tmx.TMXTile;
import org.andengine.extension.tmx.TMXTileProperty;
import org.andengine.extension.tmx.TMXTiledMap;
import org.andengine.extension.tmx.util.exception.TMXException;
import org.andengine.extension.tmx.util.exception.TMXLoadException;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.debug.Debug;

public class MainActivity extends SimpleBaseGameActivity  {
private TMXTiledMap mTMXTiledMap;
    private TMXLayer tmxLayer;
    private static final int CAMERA_WIDTH=550;
    private static final int CAMERA_HEIGHT=300;

    private BoundCamera mBoundChaseCamera;
    protected int mCactusCount;

@Override
public Engine onCreateEngine(EngineOptions engineOptions){
    return new LimitedFPSEngine(engineOptions,60);
}
    @Override
    public EngineOptions onCreateEngineOptions(){
        this.mBoundChaseCamera = new BoundCamera(0,0,CAMERA_WIDTH,CAMERA_HEIGHT);return new EngineOptions(true,ScreenOrientation.LANDSCAPE_FIXED,new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),this.mBoundChaseCamera);
}

    @Override
    protected void onCreateResources() {
    final TMXLoader tmxLoader = new TMXLoader(getAssets(),getTextureManager(),TextureOptions.NEAREST,mEngine.getVertexBufferObjectManager());
    try {
       this.mTMXTiledMap = tmxLoader.loadFromAsset("map/levelone.tmx");
   } catch (final TMXLoadException e){
            Debug.e(e);
        }
    }

    @Override
    protected Scene onCreateScene() {
       this.mEngine.registerUpdateHandler(new FPSLogger());
        final Scene scene = new Scene();
        this.tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0);

        scene.setChildrenVisible(false);
        scene.setBackgroundEnabled(false);
        scene.attachChild(this.tmxLayer);

        return scene;
    }

}

The line below is giving me an error :

 final TMXLoader tmxLoader = new TMXLoader(getAssets(),getTextureManager(),TextureOptions.NEAREST,mEngine.getVertexBufferObjectManager());

Here is my full Stack Trace :

Information:Gradle tasks [:app:clean, :app:generateDebugSources,
:app:generateDebugAndroidTestSources, :app:mockableAndroidJar,
:app:prepareDebugUnitTestDependencies, :app:assembleDebug]
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/math/MathUtils.java
Error:(89, 50) error: cannot find symbol method ceil(float)
Error:(163, 42) error: cannot find symbol method sin(float)
Error:(164, 44) error: cannot find symbol method cos(float)
Error:(239, 19) error: cannot find symbol method sqrt(float)
Error:(246, 19) error: cannot find symbol method sqrt(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseElasticOut.java
Error:(69, 67) error: cannot find symbol method sin(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseElasticIn.java
Error:(70, 49) error: cannot find symbol method sin(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseSineInOut.java
Error:(52, 28) error: cannot find symbol method cos(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseCircularOut.java
Error:(58, 19) error: cannot find symbol method sqrt(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseCircularIn.java
Error:(57, 21) error: cannot find symbol method sqrt(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseSineOut.java
Error:(59, 19) error: cannot find symbol method sin(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/modifier/ease/EaseSineIn.java
Error:(59, 20) error: cannot find symbol method cos(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/adt/transformation/Transformation.java
Error:(122, 30) error: cannot find symbol method sin(float)
Error:(123, 30) error: cannot find symbol method cos(float)
Error:(139, 30) error: cannot find symbol method sin(float)
Error:(140, 30) error: cannot find symbol method cos(float)
Error:(160, 30) error: cannot find symbol method sin(float)
Error:(161, 30) error: cannot find symbol method cos(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/levelstats/LevelStatsDBConnector.java
Error:(12, 23) error: package org.apache.http does not exist
Error:(13, 23) error: package org.apache.http does not exist
Error:(14, 23) error: package org.apache.http does not exist
Error:(15, 30) error: package org.apache.http.client does not exist
Error:(16, 37) error: package org.apache.http.client.entity does not exist
Error:(17, 38) error: package org.apache.http.client.methods does not exist
Error:(18, 35) error: package org.apache.http.impl.client does not exist
Error:(19, 31) error: package org.apache.http.message does not exist
Error:(82, 12) error: cannot find symbol class HttpClient
Error:(82, 40) error: cannot find symbol class DefaultHttpClient
Error:(83, 12) error: cannot find symbol class HttpPost
Error:(83, 36) error: cannot find symbol class HttpPost
Error:(86, 17) error: cannot find symbol class NameValuePair
Error:(86, 63) error: cannot find symbol class NameValuePair
Error:(88, 29) error: cannot find symbol class BasicNameValuePair
Error:(89, 29) error: cannot find symbol class BasicNameValuePair
Error:(90, 29) error: cannot find symbol class BasicNameValuePair
Error:(91, 29) error: cannot find symbol class BasicNameValuePair
Error:(92, 29) error: cannot find symbol class BasicNameValuePair
Error:(94, 29) error: cannot find symbol class UrlEncodedFormEntity
Error:(97, 12) error: cannot find symbol class HttpResponse
Error:(100, 23) error: cannot find symbol variable HttpStatus
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/util/algorithm/path/astar/EuclideanHeuristic.java
Error:(40, 19) error: cannot find symbol method sqrt(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/opengl/texture/atlas/bitmap/source/decorator/ColorSwapBitmapTextureAtlasSourceDecorator.java
Error:(7, 24) error: cannot find symbol class AvoidXfermode
Error:(8, 38) error: package android.graphics.AvoidXfermode does not exist
Error:(70, 31) error: cannot find symbol class AvoidXfermode
Error:(70, 86) error: cannot find symbol variable Mode
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/opengl/font/StrokeFont.java
Error:(76, 36) error: cannot find symbol method floor(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/entity/particle/ParticleSystem.java
Error:(181, 111) error: cannot find symbol method floor(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/entity/particle/emitter/CircleParticleEmitter.java
Error:(50, 54) error: cannot find symbol method cos(float)
Error:(51, 54) error: cannot find symbol method sin(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/entity/particle/emitter/CircleOutlineParticleEmitter.java
Error:(50, 54) error: cannot find symbol method cos(float)
Error:(51, 54) error: cannot find symbol method sin(float)
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/entity/modifier/PathModifier.java
/home/neelpatel104/AndroidStudioProjects/TowerFinisher/AndEngine/src/main/java/org/andengine/engine/camera/hud/controls/AnalogOnScreenControl.java
Error:(85, 39) error: cannot find symbol method cos(float)
Error:(85, 71) error: cannot find symbol method sin(float)
Error:Execution failed for task ':AndEngine:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Information:Total time: 1 mins 40.808 secs
Information:55 errors
Information:0 warnings
Information:See complete output in console

I do not understand what the problem is. This error is present everytime I try to debug the program. I even tried to reinstall andengine and the TMXTiledMAP Extension, but the error is always there. I would like it if someone would take a look at it.


Solution

  • The build failed because some classes and methods are deprecated in latest versions. You may try to decrease compileSdkVersion for your andengine build.gradle file. Also you can fix most of these errors by simple changes:

    1. Change all mathematical calls like sin, cos, floor, sqrt, ceil etc by using standard Math class: replace FloatMath.sin() to (float) Math.sin() and similar for other methods.
    2. To fix package org.apache.http does not exist error: add useLibrary 'org.apache.http.legacy' to andengine build.gradle file:

      buildscript {
          repositories {
              jcenter()
          }
          dependencies {
              classpath 'com.android.tools.build:gradle:3.0.0'
          }
      }
      
      apply plugin: 'com.android.library'
      
      android {
          compileSdkVersion 23
          //buildToolsVersion '26'
          sourceSets {
              main {
                  manifest.srcFile 'AndroidManifest.xml'
                  java.srcDirs = ['src']
                  resources.srcDirs = ['src']
                  res.srcDirs = ['res']
                  assets.srcDirs = ['assets']
              }
          }
          useLibrary 'org.apache.http.legacy' //for support 23+ sdk
      }
      ...
      
    3. Class AvoidXfermode was deprecated, so set compileSdkVersion 23 as in code above. I will be appreciated if someone describe how to fix AvoidXfermode other way, without decreasing compileSdkVersion.