Help with animation and TouchEvents

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Help with animation and TouchEvents

Postby FredyFoxX » Wed Jan 12, 2011 8:56 am

Trying to get my app to load an animation rite when it starts and if the screen is touched once play one animation then return to the first looping animation. When i run on my emulator it does not run just force shutdown. This is what i have so far. Any help would be greatly appreciated.



Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. [syntax=""]
  2. import android.app.Activity;
  3. import android.graphics.drawable.AnimationDrawable;
  4. import android.os.Bundle;
  5. import android.view.MotionEvent;
  6. import android.widget.ImageView;
  7.  
  8. public class HentaiWallpaper extends Activity {
  9.         AnimationDrawable       frameAnimation;
  10.         AnimationDrawable       frameAnimation2;
  11.        
  12.         public void onCreate(Bundle savedInstanceState) {
  13.                 super.onCreate(savedInstanceState);
  14.                 setContentView(R.layout.main);
  15.  
  16.                
  17.                 frameAnimation.start();
  18.         }
  19.  
  20.         private void loadAnimation() {
  21.                 frameAnimation = new AnimationDrawable();
  22.                 frameAnimation.addFrame(getResources().getDrawable(R.drawable.frame0), 75);
  23.                 frameAnimation.addFrame(getResources().getDrawable(R.drawable.frame01), 75);
  24.                 frameAnimation.addFrame(getResources().getDrawable(R.drawable.frame02), 75);
  25.                
  26.                 frameAnimation.setOneShot(false);
  27.  
  28.                 ImageView img = (ImageView) findViewById(R.id.imageHolder);
  29.                 img.setBackgroundDrawable(frameAnimation);
  30.  
  31.         }
  32.         private void Animation2(){
  33.                 frameAnimation2 = new AnimationDrawable();
  34.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame0),85);
  35.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame1),85);
  36.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame2),85);
  37.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame3),85);
  38.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame4),85);
  39.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame5),85);
  40.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame6),85);
  41.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame7),85);
  42.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame8),85);
  43.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame9),85);
  44.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame10),85);
  45.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame11),85);
  46.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame12),85);
  47.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame13),85);
  48.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame14),85);
  49.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame15),85);
  50.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame16),85);
  51.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame17),85);
  52.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame18),85);
  53.                 frameAnimation2.addFrame(getResources().getDrawable(R.drawable.frame19),85);
  54.                
  55.                 frameAnimation2.setOneShot(true);
  56.                 ImageView img = (ImageView) findViewById(R.id.imageHolder);
  57.                 img.setBackgroundDrawable(frameAnimation2);
  58.         }
  59.         public boolean onTouchEvent(MotionEvent event) {
  60.                 if (event.getAction() == MotionEvent.ACTION_DOWN) {
  61.                         if (frameAnimation.isRunning())
  62.                                 frameAnimation.stop();
  63.                         else
  64.                                 frameAnimation.start();
  65.                 }
  66.                
  67.                 return super.onTouchEvent(event);
  68.         }
  69.  
  70.         @Override
  71.         protected void onDestroy() {
  72.                 super.onDestroy();
  73.                 frameAnimation.stop();
  74.         }
  75.  
  76. }[/syntax]
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
FredyFoxX
Freshman
Freshman
 
Posts: 5
Joined: Fri Jan 07, 2011 8:28 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests