Skip to content

Crazy blog

No money, no honey, no funny…

Monthly Archives: June 2011

I has problem with install android sdk thought internet connection. So I found another way to install it in simple way.

1. Download and install: http://dl.google.com/android/installer_r11-windows.exe

Create folder temp in folder installed, example: C:\Program Files\Android\android-sdk\temp

2. Download sdk platform:

Android SDK Platform 2.1

Android SDK Platform 2.2

3. Download platforms tools: http://dl-ssl.google.com/android/repository/platform-tools_r05-windows.zip

4. You can download more version if need, here is it: http://dl-ssl.google.com/android/repository/repository.xml 

5. Copy and extract all download zip file to temp foder.

6. Run SDK Manager (C:\Program Files\Android\android-sdk\SDK Manager.exe)

6. It will ask choose package to install, then click Cancel

7. Choose available packages, then choose Android repository, and choose the SDK platform that u already download zip. In this case it is SDK platform android 2.2

8. Click Install Selected > Install > Done.

9. Hope you can install Android SDK fast, and you can upgrade new version later.

BaseGameActivity:
The BaseGameActivity is the root of a game, that contains an Engine and manages to create a SurfaceView the contents of the Engine will be drawn into. There is always exactly one Engine for one BaseGameActivity. You can proceed from one BaseGameActivity to another using common Android mechanisms.

Engine:
The Engine make the game proceed in small discrete steps of time. The Engine manages to synchronize a periodic drawing and updating of the Scene, which contains all the content that your game is currently handling actively. There usually is one Scene per Engine, except for the SplitScreenEngines.

IResolutionPolicy:
An implementation of the IResolutionPolicy interface is part of the EngineOptions. It tells AndEngine how to deal with the different screen-sizes of different devices. I.e. RatioResolutionPolicy will maximize the SurfaceView to the limiting size of the screen, while keeping a specific ratio. That means objects won’t be distorted while the SurfaceView has the maximum size possible.

Camera:
A Camera defines the rectangle of the scene that is drawn on the screen, as not the whole scene is visible all the time. Usually there is one Camera per Scene, except for the SplitScreenEngines. There are subclasses that allow zooming and smooth position changes of the Camera.

Scene:
The Scene class is the root container for all objects to be drawn on the screen. A Scene has a specific amount of Layers, which themselves can contain a (fixed or dynamic) amount of Entities. There are subclasses, like the CameraScene/HUD/MenuScene that are drawing themselves to the same position of the Scene no matter where the camera is positioned to.

Entity:
An Entitiy is an object that can be drawn, like Sprites, Rectangles, Text or Lines. An Entity has a position/rotation/scale/color/etc…

Texture:
A Texture is a ‘image’ in the memory of the graphics chip. On Android the width and height of a Texture has to be a power of 2. Therefore AndEngine assembles a Texture from a couple of ITextureSources, so the space can be used better.

ITextureSource:
An implmentation of the ITextureSource-interface like AssetTextureSource manages to load an image onto a specific position in the Texture.

TextureRegion:
A TextureRegion defines a rectangle on the Texture. A TextureRegion is used by Sprites to let the system know what part of the big Texture the Sprite is showing.

PhysicsConnector:
A PhysicsConnector manages to update the AndEngine-Shapes (like Rectangles/Sprites/etc…) when their physics representations “bodies” change. Once using Physics (and a PhysicsConnector) with an AndEngine-Shape you’d disable the Physics calculated by AndEngine itself, by calling setUpdatePhysics(false) to the Shape. Changes made to the AndEngine-Shape are not reflected in the Physics – you have to call the methods on the Body object you have used to create the PhysicsConnector.

1. Create Android project as normal, class activity example AndEngineActivity

2. Add AndEngine.Jar for build path (right click on Project > properties > java build path)

3. Add user permission in Manifest.xml, after <uses-sdk android:minSdkVersion=”7″ />

<uses-permission android:name=”android.permission.WAKE_LOCK”/>

4. Create folder assets/gfx, then add file: face_box.png (must be png format)

5. Edit code for class AndEngineActivity

package com.mylib.game;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public class AndEngineActivity extends BaseGameActivity {

// ===========================================================
// Constants
// ===========================================================

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

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

private Camera mCamera;
private Texture mTexture;
private TextureRegion mFaceTextureRegion;
private Sprite mFaceToRemove;

@Override
public Engine onLoadEngine() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}

@Override
public void onLoadResources() {
this.mTexture = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mFaceTextureRegion = TextureRegionFactory.createFromAsset(mTexture, this, “gfx/face_box.png“,0,0);
this.mEngine.getTextureManager().loadTexture(mTexture);
}

@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());

final Scene scene = new Scene(1);
scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

//mFaceToRemove = new Sprite(100,100,mFaceTextureRegion);
final int centerY = (CAMERA_HEIGHT – this.mFaceTextureRegion.getHeight()) / 2;
final int centerX = (CAMERA_WIDTH – this.mFaceTextureRegion.getWidth()) / 2;

Sprite face = new Sprite(centerX, centerY,mFaceTextureRegion) {
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() – this.getWidth() / 2, pSceneTouchEvent.getY() – this.getHeight() / 2);
return true;
}
};
//scene.attachChild(mFaceToRemove);
scene.attachChild(face);

scene.registerTouchArea(face);
scene.setTouchAreaBindingEnabled(true);

return scene;
}

@Override
public void onLoadComplete() {

}

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

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

}

import ​android.app.Activity;
import​ android.os.Bundle;
import android.util.Log;

public ​class ​MainActivity ​extends ​Activity​{
​​​​String tag = “Events”;
​​​​@Override
​​​​public​void​onCreate(Bundle​savedInstanceState)​{
​​​​​​​​super.onCreate(savedInstanceState);
​​​​​​​​setContentView(R.layout.main);
​​​​​​​​Log.d(tag, “In the onCreate() event”);
}
​​​​public void onStart()
​​​​{
​​​​​​​​super.onStart();
​​​​​​​​Log.d(tag, “In the onStart() event”);
​​​​}
​​​​public void onRestart()
​​​​{
​​​​​​​​super.onRestart();
​​​​​​​​Log.d(tag, “In the onRestart() event”);
​​​​}
​​​​public void onResume()
​​​​{
​​​​​​​​super.onResume();
​​​​​​​​Log.d(tag, “In the onResume() event”);
​​​​}
​​​​public void onPause()
​​​​{
​​​​​​​​super.onPause();
​​​​​​​​Log.d(tag, “In the onPause() event”);
​​​​}
​​​​public void onStop()
​​​​{
​​​​​​​​super.onStop();
​​​​​​​​Log.d(tag, “In the onStop() event”);
​​​​}
​​​​public void onDestroy()
​​​​{
​​​​​​​​super.onDestroy();
​​​​​​​​Log.d(tag, “In the onDestroy() event”);
​​​​}
}

I love android, and I just want to develop app. Here is the steps I did (window 7 – 32 bit)

1. Install Java sdk, also set path JAVA_HOME

2. Install Eclipse

3. Install Android SDK

4. Start Eclipe, select Help > Install new software

5. Type: https://dl-ssl.google.com/android/eclipse/ in Work with and click Select All

6. Click Finish

7. From Eclipse, choose Window menu > Android SDK and AVD Manager

8. Click Add new and type AVD name, choose target , sd card as image, should not choose Enable Snapshot

9. Click Create AVD

10. Click Start and the android simulator will display ^_^