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 }
func (t *TestScene) OnMainMenuCallback(_ cc.Node) { cc.Log("begin OnMainMenuCallback") scene := cc.NewScene() layer := t.controller.Clone().Layer scene.AddChild(layer) //TODO transition progress cc.Director().RunScene(scene) }
func (a *actionMove) centerSprites() { winSize := cc.Director().GetWinSize() a.Grossini.SetPositionX(winSize.Width() / 2) a.Grossini.SetPositionY(winSize.Height() / 2) a.Tamara.SetPositionX(winSize.Width() / 4) a.Tamara.SetPositionY(winSize.Height() / 2) a.Kathia.SetPositionX(3 * winSize.Width() / 4) a.Kathia.SetPositionY(winSize.Height() / 2) }
func main() { cc.Game.SetOnStart(func() { cc.Log("starts from main.go") cc.View().AdjustViewPort(true) cc.View().SetDesignResolutionSize(800, 450, cc.SHOW_ALL) cc.View().ResizeWithBrowserSize(true) cc.LoaderScene().Preload(resouces, func() { cc.Director().RunScene(NewHelloWorldScene()) }) }) cc.Game.Run() }
func main() { cc.Game.SetOnStart(func() { cc.Log("starts from main.go", "begin tests") cc.View().AdjustViewPort(true) cc.View().SetDesignResolutionSize(800, 450, cc.SHOW_ALL) cc.View().ResizeWithBrowserSize(true) cc.LoaderScene().Preload(resources, func() { scene := cc.NewScene() scene.AddChild(test.NewTestController(testNames, resources).Layer) cc.Director().RunScene(scene) }) }) cc.Game.Run() }
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 }