예제 #1
0
func NewTestScene(controller *TestController) *TestScene {
	testScene := &TestScene{
		Scene:      cc.NewScene(),
		controller: controller,
	}

	label := cc.NewLabelTTF("Main Menu", "Arial", 20)
	menuItem := cc.NewMenuItemLabelAllArgs(label, testScene.OnMainMenuCallback, testScene.Scene)
	menuItem.SetPosition(cc.NewPoint(cc.WinSize().Width()-50, 25))

	menu := cc.NewMenu(menuItem)
	menu.SetPosition(cc.NewPoint(0, 0))

	testScene.Scene.AddChildWithOrder(menu, 1)

	return testScene
}
예제 #2
0
func NewHelloWorldLayer() cc.Layer {
	layer := &helloworldLayer{Layer: cc.NewLayer(), sprite: nil}

	size := cc.WinSize()

	closeNormal := resouces["CloseNormal_png"].(string)
	closeSelected := resouces["CloseSelected_png"].(string)
	closeCallback := func(_ cc.Node) {
		cc.Log("Menu is clicked!")
	}

	closeItem := cc.NewMenuItemImageAllArgs(
		&closeNormal,
		&closeSelected,
		nil,
		&closeCallback,
		layer.Layer)

	closeItem.Attr(map[string]interface{}{
		"x":       size.Width() - 20,
		"y":       20,
		"anchorX": 0.5,
		"anchorY": 0.5,
	})

	menu := cc.NewMenu(closeItem)
	//menu.SetPosition(cc.NewPoint(0, 0)) works too
	menu.SetPositionX(0)
	menu.SetPositionY(0)
	layer.AddChildWithOrder(menu, 1)

	//helloLabel := js.Global.Get("cc").Get("LabelTTF").New("Hello World", "Arial", 38)
	helloLabel := cc.NewLabelTTF("Hello World", "Arial", 38)

	// position the label on the center of the screen
	helloLabel.SetPosition(cc.NewPoint(size.Width()/2, 0))

	// add the label as a child to this layer
	layer.AddChildWithOrder(helloLabel, 5)

	// add "HelloWorld" splash screen"
	layer.sprite = cc.NewSprite(resouces["HelloWorld_png"].(string))
	layer.sprite.Attr(map[string]interface{}{
		"x":        size.Width() / 2,
		"y":        size.Height() / 2,
		"scale":    0.5,
		"rotation": 180,
	})
	layer.AddChildWithOrder(layer.sprite, 0)

	layer.sprite.RunAction(
		cc.NewSequence(
			cc.NewRotateTo(2, 0, 0),
			cc.NewScaleTo(2, 1, 1),
		),
	)

	helloLabel.RunAction(
		cc.NewSpawn(
			cc.NewMoveBy(2.5, cc.NewPoint(0, size.Height()-40)),
			cc.NewTintTo(2.5, 255, 125, 0),
		),
	)

	return layer.Layer
}