開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- three.js (JavaScript Library)
- Safari (Web Browser)
3D Game Programming for Kids: Create Interactive Worlds with JavaScript (Chris Strom(著)、Pragmatic Bookshel)の Chapter 3(Project: Making an Avatar)の Challenge: Start/Stop Animation を取り組んでみる。
コード(Emacs)
var isCartwheeling = false;
var isFlipping = true;
var animate = function () {
requestAnimationFrame(animate);
if (isCartwheeling) {
avatar.rotation.z += 0.05;
}
if (isFlipping) {
avatar.rotation.y += 0.05;
}
renderer.render(scene, camera);
}
animate();
document.addEventListener('keydown', function (event) {
var code = event.keyCode;
if (code === 37) {
avatar.position.x -= 5;
} else if (code === 38) {
avatar.position.z -= 5;
} else if (code === 39) {
avatar.position.x += 5;
} else if (code === 40) {
avatar.position.z += 5;
} else if (code === 67) {
isCartwheeling = !isCartwheeling;
} else if (code === 70) {
isFlipping = !isFlipping;
}
})
0 コメント:
コメントを投稿