Skip to content

Instantly share code, notes, and snippets.

@nakosung
Created October 7, 2013 08:35
Show Gist options
  • Save nakosung/6864513 to your computer and use it in GitHub Desktop.
Save nakosung/6864513 to your computer and use it in GitHub Desktop.
cc.Menu.extend = cc.Class.extend
cc.MenuItemLabel.extend = cc.Class.extend
ZoomActionTag = 0x60c05002
MyItem = cc.MenuItemLabel.extend
onEnter : ->
_was_selected = false
check = =>
_selected = @isSelected()
if _selected and not _was_selected
_was_selected = true
@selected_v2()
else if not _selected and _was_selected
_was_selected = false
@unselected_v2()
@schedule check, 0.01
initWithString : (text,callback) ->
@label = cc.LabelTTF.create text, 'Arial', 30
@sprite = cc.Sprite.create 'cpu_fan_icon.jpg'
@addChild @sprite
@sprite.setOpacity 0
@setContentSize @label.getContentSize()
@initWithLabel @label, callback
selected_v2 : ->
@killDefaultAction()
@sprite.runAction cc.FadeIn.create(0.1)
@label.runAction cc.TintTo.create(0.1,255,0,0)
# @runAction cc.ScaleTo.create(0.01,10)
unselected_v2 : ->
@killDefaultAction()
@sprite.runAction cc.FadeOut.create(0.1)
@label.runAction cc.TintTo.create(0.1,255,255,255)
# @runAction cc.ScaleTo.create(0.3,1)
killDefaultAction : ->
@stopActionByTag ZoomActionTag
#@stopAction action if action?
#@stopAllActions()
setFontSize : (args...) ->
@label.setFontSize args...
@setContentSize @label.getContentSize()
setFontName : ->
MyItem.create = (args...) ->
item = new MyItem()
item.initWithString args...
item
MyMenu = cc.Menu.extend
initWithArray : (array) ->
@_super array
array.forEach (x,i) ->
x.setOpacity 0
x.runAction cc.FadeIn.create(i*0.2)
addChild : (x) ->
@items ?= []
@items.push x
flush : ->
@initWithArray @items
# menu = new MyMenu()
# menu.setPosition cc.p 400, 400
# myItem.initWithString 'test', ->
# menu.initWithArray [ myItem, cc.MenuItemFont.create 'test2', -> ]
# menu.alignItemsVertically()
# layer.addChild menu
item = MyItem.create '다른 게임 선택하기', -> self.emit 'destroy'
#item = cc.MenuItemFont.create '다른 게임 선택하기', -> self.emit 'destroy'
item.setAnchorPoint cc.p 1, 1
item.setFontSize 50
item.setFontName 'NanumPen.otf'
menu = new MyMenu()
temp = [1..8].map (x) ->
MyItem.create 'Test' + x + 'blamlkemlkemlkemlke', ->
[item, temp...].forEach (x) ->
menu.addChild x
menu.flush()
menu.setAnchorPoint cc.p 1, 1
menu.alignItemsVertically()
{width,height} = director.getWinSize()
menu.setPosition cc.p width/2,height/2
layer.addChild menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment