Skip to content

Instantly share code, notes, and snippets.

@tsuwatch
Forked from mizchi/main.coffee
Created October 4, 2012 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsuwatch/3831946 to your computer and use it in GitHub Desktop.
Save tsuwatch/3831946 to your computer and use it in GitHub Desktop.
mmd.gl.enchant.js
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