Android Open Source - BobEngine Main Activity






From Project

Back to project page BobEngine.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project BobEngine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package bobby.example.cameraexample;
/*from  w w w.j  av a  2  s . c  o m*/
import android.os.Bundle;

import bobby.engine.bobengine.BobActivity;
import bobby.engine.bobengine.BobView;
import bobby.engine.bobengine.GameObject;
import bobby.engine.bobengine.Graphic;
import bobby.engine.bobengine.Room;

public class MainActivity extends BobActivity {

    BobView view;        // View for displaying BobEngine content
    Room room;           // Room for containing GameObjects
    GameObject object;   // An object to display
    Graphic g;           // The graphic to give to our object

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        view = new BobView(this) {
            @Override
            protected void onCreateGraphics() {
                g = getGraphicsHelper().addGraphic(R.drawable.ic_launcher);
            }

            @Override
            protected void onCreateRooms() {

                /**
                 * Room and object initialization
                 */
                room = new Room(view);

                object = new GameObject(room.nextInstance(), room);
                object.x = room.getWidth() / 2;                     // Center of the screen when camera (x,y) is (0,0)
                object.y = room.getHeight() / 2;                    // Center of the screen
                object.width = room.getWidth() / 10;
                object.height = object.width;
                object.setGraphic(g, 1);

                room.addObject(object);

                goToRoom(room); // This is how we tell BobEngine which room to update and draw!!

                /**
                 * Camera function tests.
                 */

                // Position
                /**
                 * (0,0) is the default camera position. Moving the camera will translate the objects
                 * in the opposite direction. For example: room.setCameraX(100) would translate
                 * all objects in the room to the left by 100 pixels. It will appear as if the camera
                 * moved to the right.
                 */
                room.setCameraX(0);
                room.setCameraY(0);

                // Zoom
                /**
                 * 1 is the default zoom. Setting the zoom to a larger number will move the camera
                 * out further away from the objects. Setting the zoom to a fraction < 1 will move the
                 * camera in closer to the objects.
                 */
                room.setCameraZoom(1);

                // Anchor
                /**
                 * (0,0) is the default anchor point. The anchor is the point that will remain in place
                 * when zooming in and out. (0,0) is the bottom left corner. If the subject of your
                 * screen (player, etc...) is in the center of the screen, you may want to set the
                 * anchor to the center of the screen: (room.getWidth() / 2, room.getHeight() / 2).
                 * Then, the player will remain in the center when zooming in and out.
                 */
                room.setCameraAnchor(getWidth() / 2, getHeight() / 2);
            }
        };

        setContentView(view);
    }
}




Java Source Code List

bobby.engine.bobengine.BobActivity.java
bobby.engine.bobengine.BobActivity.java
bobby.engine.bobengine.BobRenderer.java
bobby.engine.bobengine.BobRenderer.java
bobby.engine.bobengine.BobView.java
bobby.engine.bobengine.BobView.java
bobby.engine.bobengine.BuildConfig.java
bobby.engine.bobengine.BuildConfig.java
bobby.engine.bobengine.GameObject.java
bobby.engine.bobengine.GameObject.java
bobby.engine.bobengine.Graphic.java
bobby.engine.bobengine.Graphic.java
bobby.engine.bobengine.GraphicsHelper.java
bobby.engine.bobengine.GraphicsHelper.java
bobby.engine.bobengine.NumberDisplay.java
bobby.engine.bobengine.NumberDisplay.java
bobby.engine.bobengine.Room.java
bobby.engine.bobengine.Room.java
bobby.engine.bobengine.SoundPlayer.java
bobby.engine.bobengine.SoundPlayer.java
bobby.engine.bobengine.SplashActivity.java
bobby.engine.bobengine.SplashActivity.java
bobby.engine.bobengine.Touch.java
bobby.engine.bobengine.Touch.java
bobby.engine.template.AnObject.java
bobby.engine.template.AnObject.java
bobby.engine.template.BuildConfig.java
bobby.engine.template.BuildConfig.java
bobby.engine.template.GameView.java
bobby.engine.template.GameView.java
bobby.engine.template.MainActivity.java
bobby.engine.template.MainActivity.java
bobby.engine.template.StartRoom.java
bobby.engine.template.StartRoom.java
bobby.engine.touchinput.AnObject.java
bobby.engine.touchinput.AnObject.java
bobby.engine.touchinput.GameView.java
bobby.engine.touchinput.GameView.java
bobby.engine.touchinput.MainActivity.java
bobby.engine.touchinput.MainActivity.java
bobby.engine.touchinput.StartRoom.java
bobby.engine.touchinput.StartRoom.java
bobby.example.bobengineexample.Android.java
bobby.example.bobengineexample.BuildConfig.java
bobby.example.bobengineexample.GameView.java
bobby.example.bobengineexample.MainActivity.java
bobby.example.bobengineexample.StartRoom.java
bobby.example.cameraexample.ApplicationTest.java
bobby.example.cameraexample.MainActivity.java
com.bobbyloujo.jumpybug.ApplicationTest.java
com.bobbyloujo.jumpybug.Background.java
com.bobbyloujo.jumpybug.Bug.java
com.bobbyloujo.jumpybug.Flower.java
com.bobbyloujo.jumpybug.GameOver.java
com.bobbyloujo.jumpybug.GameRoom.java
com.bobbyloujo.jumpybug.GameView.java
com.bobbyloujo.jumpybug.MainActivity.java
com.bobbyloujo.jumpybug.StartRoom.java