ulfben

BasicInputManager (Android)

Feb 15th, 2017
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class BasicInputManager extends InputManager
  2.         implements View.OnTouchListener {
  3.    
  4.     BasicInputManager(View view){
  5.         view.findViewById(R.id.keypad_up).setOnTouchListener(this);
  6.         view.findViewById(R.id.keypad_down).setOnTouchListener(this);
  7.         view.findViewById(R.id.keypad_left).setOnTouchListener(this);
  8.         view.findViewById(R.id.keypad_right).setOnTouchListener(this);
  9.         view.findViewById(R.id.keypad_jump).setOnTouchListener(this);
  10.     }
  11.    
  12.     @Override
  13.     public boolean onTouch(final View v, final MotionEvent event) {
  14.         int action = event.getActionMasked();
  15.         int id = v.getId();
  16.         if(action == MotionEvent.ACTION_DOWN){// User started pressing a key
  17.             if(id == R.id.keypad_up){
  18.                 mVerticalFactor -= 1;
  19.             }else if (id == R.id.keypad_down) {
  20.                 mVerticalFactor += 1;
  21.             }
  22.             if (id == R.id.keypad_left) {
  23.                 mHorizontalFactor -= 1;
  24.             } else if(id == R.id.keypad_right) {
  25.                 mHorizontalFactor += 1;
  26.             }
  27.             if (id == R.id.keypad_jump) {
  28.                 mIsJumping = true;
  29.             }
  30.         } else if(action == MotionEvent.ACTION_UP) {
  31.             if (id == R.id.keypad_up) {
  32.                 mVerticalFactor += 1;
  33.             } else if (id == R.id.keypad_down) {
  34.                 mVerticalFactor -= 1;
  35.             }
  36.             if (id == R.id.keypad_left) {
  37.                 mHorizontalFactor += 1;
  38.             } else if (id == R.id.keypad_right) {
  39.                 mHorizontalFactor -= 1;
  40.             }
  41.             if (id == R.id.keypad_jump) {
  42.                 mIsJumping = false;
  43.             }
  44.         }
  45.         return false;
  46.     }
  47. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×