캔버스를 사용할 때 위치 변수는 픽셀을 나타내고 부동 소수점 값은 의미가 없으므로 정수 값이어야한다고 생각합니다. 콘솔을 열고 sceneManager.currentScene.GameplayLayer.ball.position.x
에 입력하면 정말 긴 십진수가됩니다. 나는 때때로 공이 1px 대신에 2px 움직이는 것을 제안하는 OP에 대한 의견이 뭔가있을 수 있다고 생각합니다. 당신이 당신의 위치를 업데이트 할 때 당신은 부동 소수점 값으로 끝납니다.
때로는 아래쪽으로 높은 픽셀 위치로 올림하는 경우가 있습니다. 나는 바닥이나 천정을 그렇게하려고 노력할 것이다 :
this.position.x += Math.floor(this.speed * 100 * deltaTime * Math.cos(directionInRadians));
this.position.y += Math.floor(this.speed * 100 * deltaTime * Math.sin(directionInRadians));
나는이 두 가지 변화를 만들고 그것의 행동을 볼 것이다.
편집 : 논리를 단순화하기 위해 질문을 편집 했으므로. 시도 할 항목을 제안 할 수 있습니다.이 클립은 내가 항상 사용하는 Clock 객체를 사용하는 것입니다. 그것은 나에게 부드러운 애니메이션을 제공하고 오히려 간단합니다. 그것은 clock that Three.JS uses을 기반으로하므로 체크 아웃 할 수도 있습니다. 자신 만의 코드를 사용하고자 할 때조차도이 기성품 솔루션을 사용해보고 동일한 결과를 얻을 수 있는지 확인하십시오. 그것은 나를 위해 잘 작동하는 것 같다. 또한 shim을 사용하여 게임 기능의 호출이 requestAnimFrame(game);
이되도록 했습니까?
var Clock = function() {
/** Member startTime will remain fixed at its integer
millisecond value returned by Date.now(). Will always
be equal to the time the clock was started */
this.startTime = Date.now();
/** Member ms is updated by tick() to a integer value reprsenting
the number of milliseconds between the epoch (January 1, 1970)
and the current date and time of the system. */
this.ms = this.startTime;
this.last = this.startTime; /** millis at last call to tick() */
this.time = 0; /** ms in floating point seconds not millis */
/** Member dt is updated by tick() to an integer value representing
the number of milliseconds since the last call to tick(). */
this.dt = 0;
this.delta = 0; /** dt in floating point seconds not millis */
/** Member fps is updated by tick() to a floating point value representing
frames per second, updated and averaged approximately once per second */
this.fps = 0.0;
/** Member frameCount is updated to an integer value representing the
total number of calls to tick() since the clock was created. */
this.frameCount = 0;
/** The frameCounter member is a flag you can turn off if you don't need to
calculate the frameCount or do the average FPS calculation every second */
this.frameCounter = true;
/** Private globals needed to calculcate/average fps over eachs second */
var timeToUpdate = 0;
var framesToUpdate = 0;
/************************************************************************************
The tick() method updates ALL the Clock members, which should only
be read from and never written to manually. It is recommended that
tick() is called from a callback loop using requestAnimationFrame
Learn more: http://paulirish.com/2011/requestanimationframe-for-smart-animating/
*************************************************************************************/
this.tick = function() {
/** This is a new frame with it's very own unique number */
if (this.frameCounter) this.frameCount++;
/** Set the private currentTime variable */
this.ms = Date.now();
/** Update time delta and immediately set last time to
be as accurate as possible in our timings. */
this.dt = this.ms - this.last;
this.last = this.ms;
/** Calculate floating-point delta and increment time member */
this.delta = 0.001 * this.dt;
this.time += this.delta;
/** Calculate private temp variables for fps calculation */
if (this.frameCounter) {
timeToUpdate += this.dt;
framesToUpdate++;
if (timeToUpdate > 1000) {
this.fps = Math.round((framesToUpdate * 1000)/timeToUpdate);
framesToUpdate = 0;
timeToUpdate = 0;
}
}
}
}
당신이 다음이 객체를 사용하는 경우 너무 clock = new Clock();
처럼 초기화 함수에 새로운 시계 객체를 생성하기 만하면됩니다. 그런 다음 각 애니메이션 통화에서 clock.tick()
으로 전화하십시오. clock.delta
및 clock.time
멤버에 액세스하면 델타 및 시간을 초 단위로 부동 소수점 값으로 사용할 수 있습니다. clock.dt
및 clock.ms
은 밀리 초 단위로 정수를 제공합니다. clock.fps
을 사용하여 fps에 액세스하거나 clock.frameCounter = false
을 설정하여 fps를 비활성화 할 수도 있습니다.
나는 전혀 보지 못했다. 그것은 또한 항상 '59'라고 말했다. 그게 fps 야? – Esailija
Hmmm, yes 59 초당 업데이트 수를 표시하려고했습니다. 사파리와 크롬 모두 내 Mac에서, 나는 부드럽게 움직이지 않고 패들과 공이 조금 앞으로 뛰는 것을보고 있습니다. 나는 다른 컴퓨터에서 확인해야 할 것 같아. – Quantastical
내가 정말 가깝게 보면 공이 약간 엉망이된다고 생각합니다 ... 이것은 어떤 프레임에서는 볼이 한 번에 1px 이상 움직이기 때문입니다. – Esailija