How do I make a “Hello World” with andEngine insid

2019-05-27 03:41发布

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条回答
男人必须洒脱
2楼-- · 2019-05-27 03:58

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

查看更多
登录 后发表回答