2014-01-24 2 views
1

플레이어 (사용자 팀)가 볼을 가져 왔을 때 뒤엉킨 유니티 풋볼 게임 (2D 탑 다운 뷰)이 있습니다. Texture2d [] 프레임을 사용하여 플레이어에 애니메이션을 적용합니다. 나는 48 프레임의 이미지를 가지고있다. 프레임을 32 프레임으로 줄이면 게임 속도가 빨라 집니까?유니티 게임이 지연됩니다.

이 내가 애니메이션을 어떻게,

void Update() { 
    if (players.moving == true) 
    { 
     if (timer > 0.0f) 
      timer -= Time.deltaTime; 
     if (timer <= 0.0f) 
      timer = 0.0f; 
     if (timer == 0.0f) 
      NextFrame(); 
    } 
    else 
    { 
     if (players.movingUp == true) 
      renderer.material.mainTexture = frames[0]; } 

public void NextFrame() 
{ 
    if (!play) 
     return; 
    //test velocity direction 
    if (players.movingUp == true) 
    { 
     if (northFrame >= 0 && northFrame <= 2) 
     { 
      northFrame ++; 
      renderer.material.mainTexture = frames[northFrame]; 
     } 
     else 
     { 
      northFrame = 0; 
      renderer.material.mainTexture = frames[northFrame]; 
     } 
     //renderer.material.mainTexture = frames[northFrame]; 
     //Debug.Log ("North frame: " + northFrame); 
    } 
} 

이 내 사용자 플레이어 업데이트 기능입니다.

if (players[0].GetComponent<TPCCS>().highlight == true) 
    { 
     ring1.renderer.enabled = true; 
     ring2.renderer.enabled = false; 
     ring3.renderer.enabled = false; 
     ring4.renderer.enabled = false; 
    } 

    if (players[1].GetComponent<TPCCS>().highlight == true) 
    { 
     ring1.renderer.enabled = false; 
     ring2.renderer.enabled = true; 
     ring3.renderer.enabled = false; 
     ring4.renderer.enabled = false; 
    } 

    if (players[2].GetComponent <TPCCS>().highlight == true) 
    { 
     ring1.renderer.enabled = false; 
     ring2.renderer.enabled = false; 
     ring3.renderer.enabled = false; 
     ring4.renderer.enabled = true; 
    } 
    rigidbody.freezeRotation = true; 
+0

스프라이트를 애니메이션으로 만드는 것은 트릭입니다. http://michaelcummings.net/mathoms/creating-2d-animated-sprites-using-unity-4.3#.UuYOZRCwpD_ – user3231576

+0

아, 네가 간다. 나는 어느 시점에서 4.3의 새로운 2D 기능을 실제로 확인해야합니다. 그러나 그것은 실제로 같은 원리입니다. – Bart

답변

2

프레임을 줄이거 나 만들지 않아도 빨리 테스트 할 수 있는지 여부입니다. 내 추측은 그렇습니다.하지만 여전히 어떻게 접근 할 것인가는 아닙니다. 이상적으로 당신은 개별 텍스처를 전혀 갖고 싶지 않습니다.

텍스처 전환에는 많은 비용이 듭니다. 각 프레임마다 그렇게하고 싶지는 않습니다. 여러분이 보길 원하는 것은 모든 프레임을 아틀라스 (또는 스프라이트 시트)에 결합하는 것입니다. 즉, 모든 작은 텍스처가 포함 된 하나의 큰 텍스처입니다. 예를 들어 TexturePacker로 할 수있는 것.

텍스처를 애니메이션으로 전환하는 대신 텍스처 좌표 (또는 재질에 대한 텍스처 오프셋)를 "움직이게"하여 표시 할 큰 아틀라스의 올바른 부분을 선택합니다. 이와 같이 텍스처를 전혀 바꾸지 않아 성능이 크게 향상됩니다.

+0

이와 비슷한 논의는 [Unity forums] (http://forum.unity3d.com/threads/151635-Performance-of-switching-material-textures-frequently)에서 찾을 수 있습니다. – Jerdak

+0

이 원리의 다양한 예는 http://wiki.unity3d.com/index.php?title=Animating_Tiled_texture – Bart

+0

바트에서 찾을 수 있습니다. 도움이되었습니다. 텍스처 좌표 또는 오프셋을 애니메이션 처리하는 방법을 알고 있습니까? – user3231576

관련 문제