2013-08-22 1 views
2

저는 현재 장기간 2D 게임 프로젝트를 진행 중입니다. http://www.youtube.com/watch?v=39SMSvqQSEc&feature=youtu.be 여기Java 2D Walk 애니메이션이 작동하지 않습니까?

내 spritesheet입니다 :

Sprite Sheet

그리고 여기에 렌더링 방법에 대한 코드입니다 : 때마다 캐릭터가 걸어 지금부터 나는이 만드는 정말 짜증나는 버그와 붙어

public void render(Screen screen) { 
    int xTile = 0; 
    int yTile = 28; 
    int walkingSpeed = 3; 
    int flipTop = (numSteps >> walkingSpeed) & 1; 
    int flipBottom = (numSteps >> walkingSpeed) & 1; 
    if (movingDir == 1) { 
     xTile += 2; 
    } 
    if (movingDir > 1) { 
     flipTop = 0; 
     flipBottom = ((numSteps >> 4) & 1); 
     if (movingDir == 2) { 
      flipTop = 1; 
     } 
     xTile += 4 + ((numSteps >> 3) & 1) * 2; 
    } 
    int modifier = scale; 
    int xOffset = x - 8; 
    int yOffset = y - 11; 
    if(isSwimming){ 
     int waterColor = 0; 
     yOffset += 4; 
     if(tickCount % 60 < 15){ 
      yOffset -= 1; 
      waterColor = Colors.get(-1, -1, 225, -1); 
     }else if(15 <= tickCount % 60 && tickCount % 60 < 30){ 
      yOffset -= 1; 
      waterColor = Colors.get(-1, 225, 115, -1); 
     }else if(30 <= tickCount % 60 && tickCount % 60 < 45){ 
      waterColor = Colors.get(-1, 115, -1, 225); 
     }else{ 
      yOffset -= 1; 
      waterColor = Colors.get(-1, 225, 115, -1); 
     } 
     screen.render(xOffset, yOffset + 3, 0 + 27 * 32, waterColor, 0x00, 1); // Render right half of player/water ripple 
     screen.render(xOffset + 8, yOffset + 3, 0 + 27 * 32, waterColor, 0x01, 1); // Render left half of player/water ripple 
     } 

    screen.render(xOffset + 8 * flipTop, yOffset + 0, xTile + yTile * 32, color, flipTop, scale); 
    screen.render(xOffset + 8 - 8 * flipTop, yOffset + 0, xTile + 1 + yTile * 32, color, flipTop, scale); 
    if (!isSwimming) { 
     screen.render(xOffset + 8 * flipBottom, yOffset + 8, xTile + (yTile + 1) * 32, color, flipBottom, scale); 
     screen.render(xOffset + 8 - 8 * flipBottom, yOffset + 8, xTile + 1 + (yTile + 1) * 32, color, flipBottom, scale); 
    } 

} 

그리고 화면 클래스 :

package ca.fightnight.game.gfx; 

public class Screen { 

    public static final int MAP_WIDTH = 64; 
    public static final int MAP_WIDTH_MASK = MAP_WIDTH - 1; 

    public static final byte BIT_MIRROR_X = 0x01; 
    public static final byte BIT_MIRROR_Y = 0x01; 

    public int[] pixels; 

    public int xOffset = 0; 
    public int yOffset = 0; 

    public int width; 
    public int height; 

    public SpriteSheet sheet; 

    public Screen(int width, int height, SpriteSheet sheet) { 
     this.width = width; 
     this.height = height; 
     this.sheet = sheet; 

     pixels = new int[width * height]; 
    } 

    public void render(int xPos, int yPos, int tile, int color, int mirrorDir, int scale) { 

     xPos -= xOffset; 
     yPos -= yOffset; 

     boolean mirrorX = (mirrorDir & BIT_MIRROR_X) > 0; 
     boolean mirrorY = (mirrorDir & BIT_MIRROR_Y) > 0; 
     int scaleMap = scale - 1; 
     int xTile = tile % 32; 
     int yTile = tile/32; 
     int tileOffset = (xTile << 3) + (yTile << 3) * sheet.width; 
     for (int y = 0; y < 8; y++) { 
      int ySheet = y; 
      if (mirrorY) 
       ySheet = 7 - y; 

      int yPixel = y + yPos + (y * scaleMap) - ((scaleMap << 3)/2); 

      for (int x = 0; x < 8; x++) { 
       int xSheet = x; 
       if (mirrorX) 
        xSheet = 7 - x; 
       int xPixel = x + xPos + (x * scaleMap) - ((scaleMap << 3) /2); 
       int col = (color >> (sheet.pixels[xSheet + ySheet * sheet.width + tileOffset] * 8)) & 255; 
       if (col < 255){ 
        for(int yScale = 0; yScale < scale; yScale++){ 
         if (yPixel + yScale < 0 || yPixel + yScale >= height) 
          continue; 
         for(int xScale = 0; xScale < scale; xScale++){ 
          if (xPixel + xScale < 0 || xPixel + xScale >= width) 
           continue; 
          pixels[(xPixel + xScale) + (yPixel + yScale) * width] = col; 
         } 

        } 

       } 
      } 

     } 

    } 

    public void setOffset(int xOffset, int yOffset) { 
     this.xOffset = xOffset; 
     this.yOffset = yOffset; 
    } 
} 
+0

1) * "캐릭터가 걸을 때마다 이것을 만드는 버그가 실제로 발생합니다."* 단어로 설명하십시오. 나는 비디오를 보았고 당신이 말하는 것을 아직도 확신하지 못한다. 2) 더 빨리 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –

+0

버그가 아니며 게임 기능입니다. 재미 있습니다. – arynaq

답변

0

우선 비디오가 하루를 보냈습니다. 두 번째 이유는 각 스프라이트에 전체 문자 본문을 사용하지 않으므로 애니메이션을 만들 때 혼란이 없기 때문입니다. 스프라이트 시트에서 2 개의 이미지를 사용하여 걷기 애니메이션을 만듭니다. 오른쪽으로 걸어가려면 캐릭터의 이미지가 왼발 앞으로 앞으로 오게 한 다음 오른쪽으로 앞으로 나아가려면 왼쪽으로 걷는 과정을 반복하십시오.

+0

도움을 주셔서 감사합니다,하지만 그것을 가지고 :) public static final byte BIT_MIRROR_Y = 0x01; 0x02로되어 있었다. 그래도 도와 ​​줘서 고마워! –

관련 문제