How do I make a “Hello World” with andEngine inside Android Studio on a Mac

自闭症网瘾萝莉.ら 提交于 2019-12-10 10:38:45

问题


I have tried a lot of tutorials and they are fairly complicated to follow or partly irrelevant now. How do I make a Hello World for Android using andEngine and Android Studio on a Mac?


回答1:


This is my experience as of Android Studio v1.0 on a Macintosh to setup a Hello World example. (Although it's a blue background.)

  1. Goto https://github.com/nicolasgramlich/AndEngine and clone in desktop.
  2. Create a new library by going to File -> Project Structure (⌘;) then selecting the + button on the upper left hand corner. Under "more modules select "Android Library." Change the application/library name to "AndEngine", the Module name to "AndEngine", and the Package Name to "org.andengine". On the next screen don't select an activity and click finish.
  3. Make your default module ("app" is what it was called in my project) dependent on AndEngine by clicking on the module in the project structure, then clicking the dependencies tab, then pressing the + icon on the bottom center and selecting "3. Module dependency" then select your newly created AndEngine module.
  4. Goto your cloned AndEngine folder and open the src/org/andengine folder and then select all and copy all of it into your project's AndEngine/src/main/java/org/andengine folder.
  5. Copy the android manifest file from the root of the AndEngine cloned folder into your project's AndEngine/src/main/ folder by REPLACING the old one.

  6. Copy the excerpt code below and replace the code in your MainActivity with it.


package com.mycompany.myapplication;
//package being your own, do not replace the line above

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.ui.activity.SimpleBaseGameActivity;

public class MainActivity extends SimpleBaseGameActivity {

    private Camera camera;
    private static final int CAMERA_WIDTH = 800;
    private static final int CAMERA_HEIGHT = 480;

    @Override public EngineOptions onCreateEngineOptions() {
        camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
        new FillResolutionPolicy(), camera);
        return engineOptions;
    }

    @Override protected Scene onCreateScene() {
        Scene scene = new Scene();
        scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
        return scene;
    }

    @Override protected void onCreateResources() {
    }
}

Sources:

http://www.matim-dev.com/hello-world---basic-example.html

http://geq-i.blogspot.com/2014/02/how-to-setup-andengine-in-android-studio.html

@RafaelSkubisz answer from Unable to add AndEngine to Android Studio



来源:https://stackoverflow.com/questions/27694511/how-do-i-make-a-hello-world-with-andengine-inside-android-studio-on-a-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!