카테고리 없음

[TIL] 웹소켓이 처음인 사람

WooKGOD 2024. 12. 17. 20:29
반응형

이번주는 저번주에 공부한 이론을 토대로 웹소켓에 대한 실습을 해보는 주이다. 클라이언트와 서버단을 연결해서 데이터를 주고받으면서 작업하는 것인데 생각보다 난이도가 있는 것 같다. 한쪽에서 잘 되면 반대쪽에서 문제가 계속 생긴다..


오늘 학습한 내용

 

오늘은 하루종일 웹소켓에 대해 알아보고 코딩을 해서 따로 학습한 내용이 있지는 않다. 

 

트러블슈팅

 

트러블 슈팅 내용은 있으나 아직 해결을 하지 못했다.

Score.js라는 클라이언트 부분에서 점수에 관련한 부분을 코딩한 파일이 있는데 해당 파일을 수정 후 프론트엔드 부분에서 점수가 올라가지 않는 현상이 발생했다.

 

 

게임을 진행해도 점수가 0에서 머무르는 현상이 발생.

 

현재 진행상황

 

update(deltaTime) {
    console.log('Update called with deltaTime:', deltaTime);
    if (this.currentStageId === null) return;
    
    const currentStage = this.stagesData.find(stage => stage.id === this.currentStageId);
    if (!currentStage) {
      console.error('Current stage not found:', this.currentStageId);
      return;
    }
    
    const scoreIncrement = currentStage.scorePerSecond * (deltaTime / 1000);
    this.score += scoreIncrement;

    const nextStage = this.getNextStage();
    if (nextStage && this.score >= nextStage.score && this.stageChange) {
      
      this.stageChange = false;
      
      sendEvent(11, {
        currentStage: this.currentStageId,
        targetStage: nextStage.id,
        score: Math.floor(this.score)
      });

      setTimeout(() => {
        this.stageChange = true;
      }, 1000);
    }
  }

 

deltatime 을 사용해서 점수를 계산하려고 함.

 

콘솔로그 결과 

 

 

deltatime은 잘 나오는 것이 확인되었음. 

 

이후 해결방법을 아직 찾지 못하는중. 이 글에 수정할 예정

반응형