Skip to content

Call super implementation of onGameCreated() on classes that extend SimpleBaseGameActivity #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: GLES2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@
<activity android:name=".game.racer.RacerGameActivity" android:configChanges="orientation"/>

<activity android:name=".app.cityradar.CityRadarActivity" android:configChanges="orientation"/>
<activity android:name="SurfaceGestureExample" android:configChanges="orientation"></activity>
</application>
</manifest>
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@

<!-- Apps -->
<string name="example_app_cityradar">CityRadar</string>
<string name="example_surfacegesture">Using SurfaceGesture</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
//
// @Override
// public void onGameCreated() {
// super.onGameCreated();
// this.enableOrientationSensor(this);
// }
//
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/BitmapFontExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Scene onCreateScene() {
}

public void onGameCreated() {

super.onGameCreated();
}

// ===========================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, fina

@Override
public void onGameCreated() {
super.onGameCreated();
this.showDialog(DIALOG_ALLOWDIAGONAL_ID);
}

Expand Down
1 change: 1 addition & 0 deletions src/org/andengine/examples/EaseFunctionExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTou

@Override
public void onGameCreated() {
super.onGameCreated();
this.reanimate();
}

Expand Down
1 change: 1 addition & 0 deletions src/org/andengine/examples/PhysicsMouseJointExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public Scene onCreateScene() {

@Override
public void onGameCreated() {
super.onGameCreated();
this.mEngine.enableVibrator(this);
}

Expand Down
160 changes: 160 additions & 0 deletions src/org/andengine/examples/SurfaceGestureExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package org.andengine.examples;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.Text.TextOptions;
import org.andengine.entity.util.FPSLogger;
import org.andengine.input.touch.detector.SurfaceGestureDetector.SurfaceGestureDetectorAdapter;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.HorizontalAlign;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.Toast;

/**
* (c) 2012 Ryan Antiquiera
*
* @author Ryan Antiquiera
* @since 15:44:58 - 03.14.2012
*/
public class SurfaceGestureExample extends SimpleBaseGameActivity {
// ===========================================================
// Constants
// ===========================================================

private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;

// ===========================================================
// Fields
// ===========================================================

private SurfaceGestureDetectorAdapter mSGDA;
private Font mFont;
private Scene mScene;

// ===========================================================
// Constructors
// ===========================================================

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

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

this.mSGDA = new SurfaceGestureDetectorAdapter(){

@Override
protected boolean onSingleTap() {
onSurfaceGesture("Tap");
return false;
}

@Override
protected boolean onSwipeDown() {
onSurfaceGesture("Swipe\nDown");
return false;
}

@Override
protected boolean onSwipeLeft() {
onSurfaceGesture("Swipe\nLeft");
return false;
}

@Override
protected boolean onSwipeRight() {
onSurfaceGesture("Swipe\nRight");
return false;
}

@Override
protected boolean onSwipeUp() {
onSurfaceGesture("Swipe\nUp");
return false;
}

@Override
protected boolean onDoubleTap() {
onSurfaceGesture("Double\nTap");
return false;
}

};

this.mSGDA.setEnabled(true);
}

@Override
protected void onCreateResources() {
/* Load the font we are going to use. */
FontFactory.setAssetBasePath("font/");
this.mFont = FontFactory.createFromAsset(this.getFontManager(), this.getTextureManager(), 512, 512, TextureOptions.BILINEAR, this.getAssets(), "Plok.ttf", 32, true, Color.WHITE);
this.mFont.load();
}

@Override
public EngineOptions onCreateEngineOptions() {
Toast.makeText(this, "Try tap, double tap, and swipe!", Toast.LENGTH_LONG).show();

final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}

@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());

this.mScene = new Scene();
this.mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

this.mScene.setOnSceneTouchListener(this.mSGDA);

return this.mScene;
}

// ===========================================================
// Methods
// ===========================================================

void onSurfaceGesture(CharSequence text) {
final Text gestureText = new Text(0, 0, this.mFont, text, new TextOptions(HorizontalAlign.CENTER), this.getVertexBufferObjectManager());
gestureText.setPosition((CAMERA_WIDTH - gestureText.getWidth()) * 0.5f, (CAMERA_HEIGHT - gestureText.getHeight()) * 0.5f);
gestureText.setScale(0.0f);
gestureText.registerEntityModifier(new ScaleModifier(0.5f, 0.0f, 2f));
this.mScene.attachChild(gestureText);

this.mScene.registerUpdateHandler(new TimerHandler(1.5f, new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
SurfaceGestureExample.this.mScene.unregisterUpdateHandler(pTimerHandler);
SurfaceGestureExample.this.mScene.detachChild(gestureText);
}
}));
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================

}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ private void initBackground(final IEntity pEntity) {

@Override
public void onGameCreated() {
super.onGameCreated();
this.refreshCitySprites();
}

Expand Down Expand Up @@ -376,4 +377,4 @@ public static double calculateBearing(final double pLatitude1, final double pLon
// Inner and Anonymous Classes
// ===========================================================
}
}
}
1 change: 1 addition & 0 deletions src/org/andengine/examples/benchmark/BaseBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void run() {

@Override
public void onGameCreated() {
super.onGameCreated();
this.mEngine.registerUpdateHandler(new TimerHandler(this.getBenchmarkStartOffset(), new ITimerCallback() {
@Override
public void onTimePassed(final TimerHandler pTimerHandler) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/game/pong/PongGameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void reset() {}

@Override
public void onGameCreated() {

super.onGameCreated();
}

// ===========================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public Scene onCreateScene() {

@Override
public void onGameCreated() {

super.onGameCreated();
}

// ===========================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void onTimePassed(final TimerHandler pTimerHandler) {

@Override
public void onGameCreated() {

super.onGameCreated();
}

// ===========================================================
Expand Down
2 changes: 2 additions & 0 deletions src/org/andengine/examples/launcher/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.andengine.examples.SpriteRemoveExample;
import org.andengine.examples.StrokeFontExample;
import org.andengine.examples.SubMenuExample;
import org.andengine.examples.SurfaceGestureExample;
import org.andengine.examples.TMXTiledMapExample;
import org.andengine.examples.TextBreakExample;
import org.andengine.examples.TextExample;
Expand Down Expand Up @@ -159,6 +160,7 @@ enum Example {
SPRITEREMOVE(SpriteRemoveExample.class, R.string.example_spriteremove),
STROKEFONT(StrokeFontExample.class, R.string.example_strokefont),
SUBMENU(SubMenuExample.class, R.string.example_submenu),
SURFACEGESTURE(SurfaceGestureExample.class, R.string.example_surfacegesture),
SVGTEXTUREREGION(SVGTextureRegionExample.class, R.string.example_svgtextureregion),
TEXT(TextExample.class, R.string.example_text),
TEXTBREAK(TextBreakExample.class, R.string.example_textbreak),
Expand Down
2 changes: 1 addition & 1 deletion src/org/andengine/examples/launcher/ExampleGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum ExampleGroup {
MODIFIER_AND_ANIMATION(R.string.examplegroup_modifier_and_animation,
Example.MOVINGBALL, Example.ENTITYMODIFIER, Example.ENTITYMODIFIERIRREGULAR, Example.PATHMODIFIER, Example.ANIMATEDSPRITES, Example.EASEFUNCTION, Example.ROTATION3D ),
TOUCH(R.string.examplegroup_touch,
Example.TOUCHDRAG, Example.MULTITOUCH, Example.ANALOGONSCREENCONTROL, Example.DIGITALONSCREENCONTROL, Example.ANALOGONSCREENCONTROLS, Example.COORDINATECONVERSION, Example.PINCHZOOM),
Example.TOUCHDRAG, Example.MULTITOUCH, Example.ANALOGONSCREENCONTROL, Example.DIGITALONSCREENCONTROL, Example.ANALOGONSCREENCONTROLS, Example.COORDINATECONVERSION, Example.PINCHZOOM, Example.SURFACEGESTURE),
PARTICLESYSTEM(R.string.examplegroup_particlesystems,
Example.PARTICLESYSTEMSIMPLE, Example.PARTICLESYSTEMCOOL, Example.PARTICLESYSTEMNEXUS),
MULTIPLAYER(R.string.examplegroup_multiplayer,
Expand Down