Loading Map...
Loading Map...
Log; import import import import import import import import import import import com.e3roid.E3Activity; com.e3roid.E3Engine; com.e3roid.E3Scene; com.e3roid.drawable.modifier.AlphaModifier; com.e3roid.drawable.modifier.SpanModifier; com.e3roid.drawable.sprite.TextSprite; com.e3roid.drawable.tmx.TMXException; com.e3roid.drawable.tmx.TMXLayer; com.e3roid.drawable.tmx.TMXTiledMap; com.e3roid.drawable.tmx.TMXTiledMapLoader; com.e3roid.util.Debug;
public class Bai_9_e3droidActivity extends E3Activity{ private final static int WIDTH = 320; private final static int HEIGHT = 420; private TMXTiledMap map; private ArrayList<TMXLayer> mapLayers; //-----------------------------------------------------------------------------------------@Override public E3Engine onLoadEngine() { E3Engine engine = new E3Engine(this, WIDTH, HEIGHT); engine.requestFullScreen(); engine.requestPortrait(); return engine; } //-----------------------------------------------------------------------------------------@Override public E3Scene onLoadScene() { final E3Scene scene = new E3Scene(); //Khai bo bin loadingText, khi load th ta hin th dng ch "L oading map..." final TextSprite loadingText = new TextSprite("Loading map...", 2 4, this); loadingText.move((getWidth() - loadingText.getWidth()) / 2, (getHeight() -
loadingText.getHeight()) / 2);//Ta t n g gia mn hnh loadingText.addModifier(new SpanModifier(500L, new AlphaModifier( 0, 0, 1))); scene.getTopLayer().add(loadingText); // Thc hin load maps new AsyncTask<Void,Integer,TMXTiledMap>() { @Override protected TMXTiledMap doInBackground(Void... params) { try { Log.d("doInBackground","doInBackground"); TMXTiledMapLoader mapLoader = new TMXTiledMapLoader() ;//Khai bo bin MapLoader // y ta load map t th mc Asset. Cc bn nh n h ng tn nh. ui ca n l.tmx TMXTiledMap map = mapLoader.loadFromAsset("mapgame.tm x", Bai_9_e3droidActivity.this); return map; } catch (TMXException e) { Debug.e(e.getMessage()); } return null; } @Override protected void onPostExecute(TMXTiledMap tmxTiledMap) { map = tmxTiledMap; if (tmxTiledMap != null && (mapLayers = map.getLayers()) != null) { for (TMXLayer layer : mapLayers) { Log.d("mapLayers","mapLayers"); layer.setSceneSize(getWidth(), getHeight()); //V trong maps c th c nhiu layer nn ta phi l p //ton b cc layer ny. Sau ta add vo scene. scene.getTopLayer().add(layer); scene.getTopLayer().remove(loadingText);//Ta xa b ci text hin thi khi ta load maps engine.setRefreshMode(E3Engine.REFRESH_DEFAULT); } } else {//Nu c li trong khi load th hin th thng b o sau loadingText.setText("LoadMaps Error"); loadingText.setAlpha(1); loadingText.clearModifier(); } } }.execute();
return scene;//Khi ta load maps xong ta c 1 scene nh my bi tr c } //-----------------------------------------------------------------------------------------@Override public void onLoadResources() { } //-----------------------------------------------------------------------------------------}