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
}
Esempio n. 2
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
}
Esempio n. 3
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
}
func NewTestController(testNames []Test, resources map[string]interface{}) *TestController {
	testController := &TestController{
		Layer: cc.NewLayerGradient(
			cc.NewColor(0, 0, 0, 255),
			cc.NewColor(0x46, 0x82, 0xB4, 255),
		),
		itemMenu:                nil,
		beginPos:                0,
		isMouseDown:             false,
		autoTestEnabled:         false,
		autoTestCurrentTestName: "N/A",
		curPos:                  cc.NewPoint(0, 0),
		yOffset:                 0,
		testNames:               testNames,
		resources:               resources,
	}

	//OnEnter
	testController.Layer.SetOnEnter(func() {
		testController.Layer.OnEnterSuper()
		testController.itemMenu.SetPositionX(testController.yOffset)
	})

	//globals
	director := cc.Director()
	winSize := director.GetWinSize()

	//add close menu
	closeItem := cc.NewMenuItemImage(
		resources["CloseNormal_png"].(string),
		resources["CloseSelected_png"].(string),
		func() {
			location := js.Global.Get("location")
			if location != nil {
				location.Call("replace", "http://www.google.com")
			} else {
				cc.Log("No location found, cannot close")
			}
		},
		testController.Layer)
	closeItem.SetPositionX(winSize.Width() - 30)
	closeItem.SetPositionY(winSize.Height() - 30)

	subItem1 := cc.NewMenuItemFontWithString("Automated Test: Off")
	subItem1.SetFontSize(18)
	subItem2 := cc.NewMenuItemFontWithString("Automated Test: On")
	subItem2.SetFontSize(18)

	toggleAutoTestItem := cc.NewMenuItemToggle(subItem1, subItem2)
	toggleAutoTestItem.SetCallback(testController.OnToggleAutoTest, testController.Layer)
	toggleAutoTestItem.SetPositionX(winSize.Width() - toggleAutoTestItem.GetWidth()/2 - 10)
	toggleAutoTestItem.SetPositionY(20)
	if testController.autoTestEnabled {
		toggleAutoTestItem.SetSelectedIndex(1)
	}

	menu := cc.NewMenu(closeItem, toggleAutoTestItem)
	menu.SetPositionX(0)
	menu.SetPositionY(0)

	// add menu items for tests
	testController.itemMenu = cc.NewMenu()

	//Add items for tests
	for i, testCase := range testNames {
		label := cc.NewLabelTTF(testCase.Title, "Arial", 24)
		menuItem := cc.NewMenuItemLabel(label, testController.OnMenuCallback, testController.Layer)
		testController.itemMenu.AddChildWithOrder(menuItem, i+10000)
		menuItem.SetPositionX(winSize.Width() / 2)
		menuItem.SetPositionY(winSize.Height() - (i+1)*lineSpace)
		menuItem.SetEnabled(true)
	}

	testController.itemMenu.SetWidth(winSize.Width())
	testController.itemMenu.SetHeight(1 * lineSpace)
	testController.itemMenu.SetPositionX(testController.curPos.X())
	testController.itemMenu.SetPositionY(testController.curPos.Y())
	testController.Layer.AddChild(testController.itemMenu)
	testController.Layer.AddChildWithOrder(menu, 1)

	return testController
}