Skip to content

Instantly share code, notes, and snippets.

@shinriyo
Last active Dec 14, 2015
Embed
What would you like to do?
cocos2d-x用サンプルコードをCoffeeScriptへ置き換えたhello.coffeeです。
try
cc.p = cc.p || (x, y)->
return {x:x, y:y}
cc.c4b = cc.c4 || (r, g, b, o)->
return {r: r, g: g, b: b, a: o}
cc.c3 = cc.c3 || (r, g, b)->
return {r: r, g: g, b: b}
cc.BLACK = cc.c3(0,0,0)
director = cc.Director.getInstance()
winSize = director.getWinSize()
centerPos = cc.p(winSize.width/2, winSize.height/2)
GameCreator = ()->
self = {}
self.callbacks = {}
self.getPlayScene = ()->
scene = new cc.Scene()
layer = new cc.LayerGradient()
layer.init(cc.c4b(0, 0, 0, 255), cc.c4b(0, 128, 255, 255))
lab = "Houston we have liftoff!"
label = cc.LabelTTF.create(lab, "Arial", 28)
layer.addChild(label, 1)
label.setPosition(cc.p(winSize.width / 2, winSize.height / 2))
back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack)
back.setColor(cc.BLACK)
menu = cc.Menu.create(back)
layer.addChild(menu)
menu.alignItemsVertically()
menu.setPosition(cc.p(winSize.width - 50, 50))
scene.addChild(layer)
return scene
self.getMainMenuScene = ()->
l = cc.Layer.create()
scene = cc.Scene.create()
node = cc.Reader.load("MainMenu.ccbi", this, winSize)
l.addChild(node)
scene.addChild(l)
return scene
self.getOptionsScene = ()->
l = cc.LayerGradient.create()
l.init(cc.c4b(0, 0, 0, 255), cc.c4b(255, 255, 255, 255))
scene = cc.Scene.create()
label1 = cc.LabelBMFont.create("MUSIC ON", "konqa32.fnt")
item1 = cc.MenuItemLabel.create(label1)
label2 = cc.LabelBMFont.create("MUSIC OFF", "konqa32.fnt")
item2 = cc.MenuItemLabel.create(label2)
toggle = cc.MenuItemToggle.create(item1, item2)
this.onMusicToggle = (sender)->
toggle.setCallback(this, this.onMusicToggle)
back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack)
menu = cc.Menu.create(toggle, back)
l.addChild(menu)
menu.alignItemsVertically()
menu.setPosition(centerPos)
scene.addChild(l)
return scene
self.getAboutScene = ()->
scene = cc.Scene.create()
l = cc.Layer.create()
about = cc.Reader.load("About.ccbi", this)
l.addChild(about)
back = cc.MenuItemFont.create("Back", this.callbacks, this.callbacks.onBack)
back.setColor(cc.BLACK)
menu = cc.Menu.create(back)
l.addChild(menu)
menu.alignItemsVertically()
menu.setPosition(cc.p(winSize.width - 50, 50))
scene.addChild(l)
return scene
# CCBuilder Selectors
self.onPlay = ()->
director.replaceScene(cc.TransitionFade.create(1, this.getPlayScene()))
self.onAbout = ()->
director.replaceScene(cc.TransitionZoomFlipY.create(1, this.getAboutScene()))
self.onOptions = ()->
director.replaceScene(cc.TransitionZoomFlipY.create(1, this.getOptionsScene()))
# Manual Callbacks
self.callbacks.onBack = (sender)->
director.replaceScene(cc.TransitionFlipX.create(1, self.getMainMenuScene()))
return self
game = GameCreator()
__jsc__.garbageCollect()
director.runWithScene(game.getMainMenuScene())
catch e
log(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment