Exemplo n.º 1
0
func NewScene(controller *test.TestController) *test.TestScene {
	ts := test.NewTestScene(controller)
	am := &actionMove{
		TestScene: ts,
		Grossini:  cc.NewSprite("res/Images/grossini.png"),
		Tamara:    cc.NewSprite("res/Images/grossinis_sister1.png"),
		Kathia:    cc.NewSprite("res/Images/grossinis_sister2.png"),
	}

	am.Grossini.SetScale(0.5)
	am.Tamara.SetScale(0.5)
	am.Kathia.SetScale(0.5)

	ts.Scene.AddChildWithTag(am.Grossini, 1)
	ts.Scene.AddChildWithTag(am.Tamara, 2)
	ts.Scene.AddChildWithTag(am.Kathia, 3)

	winSize := cc.Director().GetWinSize()
	am.Grossini.SetPositionX(winSize.Width() / 2)
	am.Grossini.SetPositionY(winSize.Height() / 3)
	am.Tamara.SetPositionX(winSize.Width() / 2)
	am.Tamara.SetPositionY(2 * winSize.Height() / 3)
	am.Kathia.SetPositionX(winSize.Width() / 2)
	am.Kathia.SetPositionY(winSize.Height() / 2)

	ts.Scene.SetOnEnter(func() {
		ts.Scene.OnEnterSuper()

		cc.Log("Move test started")
		am.centerSprites()
		winSize := cc.Director().GetWinSize()

		actionTo := cc.NewMoveTo(2, cc.NewPoint(winSize.Width()-40, winSize.Height()-40))
		actionBy := cc.NewMoveBy(1, cc.NewPoint(80, 80))
		actionByBack := actionBy.Reverse()

		am.Tamara.RunAction(actionTo)
		am.Grossini.RunAction(cc.NewSequence(actionBy, actionByBack))
		am.Kathia.RunAction(cc.NewMoveTo(1, cc.NewPoint(40, 40)))
	})

	ts.RunThisTest = func() {
		cc.Director().RunScene(ts.Scene)
	}
	return ts
}
Exemplo n.º 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
}