Guest User

GameDev | StackExchange - Help with Resolving Pixel Perfect

a guest
Mar 5th, 2015
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /**
  2.      * Update the player
  3.      *
  4.      * @param elapsedTime
  5.      *              Elapsed time information
  6.      * @param moveLeft
  7.      *              True if the move left control is active
  8.      * @param moveRight
  9.      *              True if the move right control is active
  10.      * @param jumpUp
  11.      *              True if the jump up control is active
  12.      * @param platforms
  13.      *              Array of platforms in the world
  14.      */
  15.     public void update(ElapsedTime elapsedTime, boolean moveLeft,
  16.             boolean moveRight, boolean jumpLeft, boolean jumpRight, boolean weaponSelect,
  17.             Terrain TerrainObj) {
  18.        
  19.         // Depending upon the left and right movement touch controls
  20.         // set an appropriate x-acceleration. If the user does not
  21.         // want to move left or right, then the x-acceleration is zero
  22.         // and the velocity decays towards zero.
  23.         if (moveLeft && !moveRight) {
  24.                 acceleration.x = -RUN_ACCELERATION;
  25.  
  26.             this.mFrameHandler.setFullImage(mGameScreen.getGame().getAssetManager().getBitmap("PlayerWalk"));
  27.             if(mFrameHandler != null && this.mFrameHandler.getRows() > 1){
  28.                 this.mFrameHandler.nextFrameVertical();
  29.             }
  30.            
  31.         } else if (moveRight && !moveLeft) {
  32.                 acceleration.x = RUN_ACCELERATION;
  33.  
  34.             Matrix matrix = new Matrix();
  35.             matrix.preScale(-1, 1);
  36.             Bitmap bitmap = mGameScreen.getGame().getAssetManager().getBitmap("PlayerWalk");
  37.             this.mFrameHandler.setFullImage(Bitmap.createBitmap(bitmap, 0,
  38.                     0, bitmap.getWidth(), bitmap.getHeight(), matrix, false));
  39.             if(mFrameHandler != null && this.mFrameHandler.getRows() > 1){
  40.                 this.mFrameHandler.nextFrameVertical();
  41.             }
  42.         } else {
  43.             acceleration.x = 0.0f;
  44.             acceleration.y = 0.0f;
  45.             velocity.x *= RUN_DECAY;
  46.         }
  47.  
  48.         // If the user wants to jump up then providing an immediate
  49.         // boost to the y velocity.
  50.         if (jumpLeft && velocity.y == 0.0f) {
  51.             velocity.y = JUMP_VELOCITY;
  52.             velocity.x = -JUMP_VELOCITY;
  53.        
  54.         }else if (jumpRight && velocity.y == 0.0f) {
  55.             velocity.y = JUMP_VELOCITY;
  56.             velocity.x = -JUMP_VELOCITY;
  57.         }
  58.         else {
  59.             velocity.y = GRAVITY;
  60.         }
  61.    
  62.         // Call the sprite's update method to apply the defined
  63.         // accelerations and velocities to provide a new position
  64.         // and orientation.
  65.         super.update(elapsedTime,TerrainObj);
  66. }
RAW Paste Data