2016-10-13 4 views
0

이 기능이 있습니다. 그것은 내 엑스 미터를 잘 채 웁니다. 그러나 exp가 다음 레벨로 남은 exp보다 크면 단지 0으로 줄어 듭니다. 내가 원하는 것은 미터가 100 %까지 채우고 그 다음 레벨에서 얻은 경험치에서 남은 양을 계속해서 채우는 것입니다. 여기에 내가 분명히되기를 바랍니다. 그렇지 않으면 말해 주면 더 잘 설명하려고 노력할 것입니다.jQuery의 Exp 측정기

이 기능은 무엇입니까? 경험이 최대 이상이되면

//These are my variables 
var currentXP = 0; 
var level = 1; 
var maxXP = 250; 

//This is my function 
function Grow() { 
    if(currentXP <= maxXP){ 
      $('#active_meter').animate({height:currentXP + "px"}, 500); 
     }else{ 
      currentXP = maxXP - currentXP; 
      level++; 
      console.log("Level: " + level); 
      $('#active_meter').animate({height:currentXP + "px"}, 500); 
      document.getElementById("level").innerHTML = level; 
    } 
    } 
+0

역행을합니다. 그것은'currentXP - maxXP'이어야합니다. – Barmar

+0

@Barmar 만약 그것이 바뀌더라도 같은 기능을합니다. 다른 아이디어가 있습니까? –

+0

그럼 당신이하려는 일을 정말로 모르겠습니다. 문제를 나타내는 실행 가능한 스택 스 니펫을 만들 수 있습니까? – Barmar

답변

1

, 최대에 그것을 애니메이션과 currentXP to the amount left over in the new level. In the completion function for that animation, set the height down to 0 '을 설정하고 새로운 특급 수준으로 그것을 애니메이션.

//These are my variables 
var currentXP = 0; 
var level = 1; 
var maxXP = 250; 

//This is my function 
function Grow() { 
    if (currentXP <= maxXP) { 
    $('#active_meter').animate({ 
     height: currentXP + "px" 
    }, 500); 
    } else { 
    currentXP = currentXP - maxXP; 
    level++; 
    console.log("Level: " + level); 
    $('#active_meter').animate({ 
     height: maxXP + "px" 
    }, 500, function() { 
     $('#active_meter').css('height', '0px').animate({ 
     height: currentXP + "px" 
     }, 500); 
    }); 
    document.getElementById("level").innerHTML = level; 
    } 
} 
+0

그건 괜찮 았어! 시간 내 주셔서 감사합니다! –