Created
September 16, 2012 14:31
-
-
Save mizchi/3732655 to your computer and use it in GitHub Desktop.
mmd.gl.enchant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enchant() | |
window.game = null | |
MODEL_PATH = 'model/Haku_Yowane.pmd' | |
MOTION_PATH = 'motion/kishimen.vmd' | |
GAME_WIDTH = 800 | |
GAME_HEIGHT = 800 | |
class MyScene3D extends Scene3D | |
constructor: -> | |
super() | |
@backgroundColor = '#ffffff' | |
@initCamera() | |
@addChild @createMikuModel() | |
@addEventListener 'touchstart', @_touchstart | |
@addEventListener 'touchmove', @_touchmove | |
createMikuModel: -> | |
miku = game.assets[MODEL_PATH].clone() | |
miku.pushAnimation(game.assets[MOTION_PATH]) | |
miku | |
initCamera: -> | |
@_camera.y = 20 | |
@_camera.z = 80 | |
@_camera.centerY = 10 | |
_touchstart: (event) => | |
@last_x = event.x | |
_touchmove: (event) => | |
r += (event.x - @last_x) / 100 | |
@_camera.x = Math.cos(r) * 80 | |
@_camera.z = Math.sin(r) * 80 | |
@last_x = event.x | |
class FPSLabel extends Label | |
constructor: -> | |
super('0') | |
@font = '24px helvetica' | |
@cnt = 0 | |
setInterval => | |
@text = @cnt | |
@cnt = 0 | |
, 1000 | |
game.rootScene.addEventListener 'enterframe', (e) => | |
@cnt++ | |
class MyGame extends Game | |
constructor: -> | |
window.game = @ | |
super(GAME_WIDTH,GAME_HEIGHT) | |
@preload [ | |
MODEL_PATH | |
MOTION_PATH | |
] | |
onload: -> | |
new MyScene3D | |
@rootScene.addChild new FPSLabel | |
window.onload = -> | |
new MyGame() | |
.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment