2014-06-12 6 views
0

내 XNA 게임에서 느려집니다. 너무 많은 적을 넣었 기 때문입니다. 제가 그들 중 일부를 제거하면 더 이상 lagg가 없습니다. 그 (것)들은 lagg를 제거하는 방법인가? 그렇게하려면 부분별로 업데이트 할 수 있다고 생각합니다. 정상적인 if()에서는 작동하지 않습니다. 내 모든 적들은 다음과 같이 넣어집니다 :지연을 제거 할 수있는 방법이 있습니까?

List<enemy1> enemies1= new List<enemy1>(); 

LoadContent() 
{ 
    foreach(enemy1 enemy in enemies1) 
     enemy.Load(Content); 

    enemies1.Add(new enemy1(new Vector2(500,500))); 
} 

Update(GameTime gameTime) 
{ 
    foreach(enemy1 enemy in enemies1) 
     enemy.Update(gameTime); 
} 

Draw(SpriteBatch spriteBatch) 
{ 
    foreach(enemy1 enemy in enemies1) 
     enemy.Draw(spriteBatch); 
} 

또한 살해 후에도 그들을 제거합니다. 지도는 좀 큰 (12700x12700)

+4

만 뷰포트 내에서 볼 수 있습니다 원수를 그릴, 아무 소용이 지연, 업데이트 또는 무승부의 원인은 무엇 – DGibbs

+0

을 볼 수없는 사람들을 렌더링하지? – OopsUser

+0

@OopsUser 적절한 렌더링. – SJD

답변

0

변경 당신이 spritebatch.begin를 호출이

Draw(SpriteBatch spriteBatch, GraphicsDevice device) 
{ 
    Point tempPoint; 
    foreach (enemy1 enemy in enemies1) 
    { 
     tempPoint = new Point((int)enemy.Position.X, (int)enemy.Position.Y) 
     if (device.Viewport.Bounds.Contains(tempPoint)) 
      enemy.Draw(spriteBatch); 
    } 
} 
+0

시도해 주셔서 감사합니다 – FkinP3rfect

+1

개체가 화면 가장자리에있을 때 문제가 발생합니다. 그러나 그것은 올바른 방향으로 나아가는 단계입니다. 문제가 발생하면 위치가 아닌 스프라이트의면을 테스트해야합니다. – quin

+0

또는 사각형을 별도의 객체에 복사하고 픽셀 무리로 '팽창'시키십시오. – Liamdev631

0

에 그리기 기능입니다()?

나는 enemy.draw()에서 호출하고 있다는 느낌이 들었습니다. 당신은 다음과 같이 한 번 호출해야합니다 :

Draw(SpriteBatch spriteBatch) 
{ 
    spriteBatch.begin(); 
    foreach(enemy1 enemy in enemies1) 
     enemy.Draw(spriteBatch); 
    spriteBatch.end(); 
} 
관련 문제