I'am learning Java,Android,Andengine only 1 month.
I would like to make the program that when the user pressed the right side of the screen animation moved to the right and when on left that to the left. But when I launch a program on my smartphone my control dont't work.
Here's my code:
Using java Syntax Highlighting
- imports .....
- public class SlimeActivity extends BaseGameActivity {
- public static Camera mCamera;
- public static final int Camera_width = 800;
- public static final int Camera_height = 480;
- private static final long delay = 1000;
- float touchX;
- float touchY;
- int touch=1;
- int xPos;
- int count;
- public static Scene MainScene;
- TiledTextureRegion _TiledSprite_TR;
- TiledTextureRegion _TiledSprite_TR2;
- TextureRegion _Sprite_TR;
- public boolean onTouchEvent(MotionEvent event)
- {
- if((event.getAction() == MotionEvent.ACTION_DOWN) || (event.getAction() == MotionEvent.ACTION_MOVE) )
- {
- touchX = event.getX();
- touchY = event.getY();
- touch=0;
- }
- else {
- if (event.getAction() == MotionEvent.ACTION_UP){
- touch = 1;
- }
- }
- return true;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
- @Override
- public Engine onLoadEngine() {
- mCamera = new Camera(0, 0, Camera_width, Camera_height);
- return new Engine(
- new EngineOptions(
- true, //режим Fullscreen = true
- ScreenOrientation.LANDSCAPE,
- new RatioResolutionPolicy(Camera_width, Camera_height),mCamera)
- .setNeedsSound(true)
- .setNeedsMusic(true));
- }
- @Override
- public void onLoadResources() {
- BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
- BitmapTextureAtlas Texture1 = new BitmapTextureAtlas(1024, 1024, TextureOptions.NEAREST_PREMULTIPLYALPHA);
- BitmapTextureAtlas Texture2 = new BitmapTextureAtlas(1024, 1024, TextureOptions.NEAREST_PREMULTIPLYALPHA);
- _TiledSprite_TR = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(Texture1, this, "anim.png", 0, 0, 9, 1);
- _Sprite_TR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(Texture2, this, "face.png", 0, 0);
- mEngine.getTextureManager().loadTextures(Texture1);
- }
- @Override
- public Scene onLoadScene() {
- MainScene = new Scene();
- if (touch==0){
- if (touchX > 400){
- AnimatedSprite _AnimSprite = new AnimatedSprite(70, 400, _TiledSprite_TR);
- _AnimSprite.registerEntityModifier(new MoveModifier(5, 70, Camera_width - _AnimSprite.getWidth(), 400, 400));
- _AnimSprite.animate(50);
- MainScene.attachChild(_AnimSprite);
- xPos = _TiledSprite_TR.getTexturePositionX();
- count = 1;
- }
- else{
- if (touchX < 400){
- AnimatedSprite _AnimSprite = new AnimatedSprite(70, 400, _TiledSprite_TR);
- _AnimSprite.registerEntityModifier(new MoveModifier(5, 70, Camera_width - _AnimSprite.getWidth(), 400, 400));
- _AnimSprite.animate(50);
- MainScene.attachChild(_AnimSprite);
- xPos = _TiledSprite_TR.getTexturePositionX();
- count = 1;
- }
- else{
- if((touch == 1) && (count==1)){
- Sprite _Sprite = new Sprite(xPos, 400, _Sprite_TR);
- MainScene.attachChild(_Sprite);
- }
- else {
- if(touch == 1){
- Sprite _Sprite = new Sprite(70, 400, _Sprite_TR);
- MainScene.attachChild(_Sprite);
- }
- }
- }
- }
- }
- else {
- Sprite _Sprite = new Sprite(70, 400, _Sprite_TR);
- MainScene.attachChild(_Sprite);
- }
- return this.MainScene;
- }
- @Override
- public void onLoadComplete() {
- // TODO Auto-generated method stub
- }
- }
Parsed in 0.051 seconds, using GeSHi 1.0.8.4

