func main() { fmt.Println("starting") GT.EngineStart() simpleScene, _ := Graphics.NewBasicScene() node := Components.NewNode("new_image") // create a png based sprite rend := Components.NewSpriteRenderer() // myImagePath, _ := filepath.Abs("../Assets/Images/test.png") rend.SetImage(GT.AssetsImages + "test.png") // attach the sprite to our node, and transform if desired node.AddComponent(rend) node.Transform().Translate(400, 400, 0) node.Transform().Scale(.7, .7, 0) // attach the node to our scene simpleScene.RootNode.AddNode(node) // start the scene to render our setup simpleScene.Start() }
func main() { fmt.Println("starting") // create the foundation: a new window, basic scene, and game component (node) GT.EngineStart() simpleScene, _ := Graphics.NewBasicScene() node := Components.NewNode("new_image") // create our renderer and our animation objects rend := Components.NewSpriteRenderer() manager := rend.AnimationManager // will be replaced by GetComponent(AnimationManager) when scripting etc. anim := Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 4, 1) // you can append other animations or images anim.AppendAnimation(Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 6, 2)) anim.AppendAnimation(Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 5, 3)) anim.AppendAnimation(Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 4, 4)) anim.AppendAnimation(Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 3, 5)) anim.AppendAnimation(Components.SpliceSpriteSheetAnimation(GT.AssetsImages+"Dog.png", 90, 58, 4, 6)) anim.Append(GT.AssetsImages + "test.png") // if you can make use of a full sprite sheet for one animation, then use the SpliceFullSpriteSheetAnimation method //anim2.SpliceFullSpriteSheetAnimation(GT.AssetsImages+"tomatohead1.png", 12, 12) anim.SetFrequency(0.25, false) // set frequency of toggle to every 1/4 second // anim.SetFrequency(10, true) // set frequency of toggle to every 10 frames // you can swap images in the animation, or remove them by number in the list anim.Reorder(1, 27) // one-based input anim.Remove(1) // remove test.png... manager.AddAnimation(anim, "dog_left_facing") manager.SetCurrentAnimation("dog_left_facing") // script components can make use of this... // animations can be retrieved for further configuration if desired anim = manager.GetAnimation("dog_left_facing") anim.SetAsOneTimeOnly(true) simpleScene.SetFPS(30) // attach the sprite to our node, and transform if desired node.AddComponent(rend) node.AddComponent(&RunLeft{}) // TODO: remove this for a scripting example //node.Transform().Scale(3, 3) // NOTE: scaling doesn't seem perfect for sub images/animations? node.Transform().Translate(400, 400, 0) // attach the node to our scene simpleScene.RootNode.AddNode(node) // start the scene to render our setup simpleScene.Start() }
func main() { fmt.Println("starting") // // defer profile.Start(profile.CPUProfile).Stop() // w := Window.NewWindowedWindow("test", 600, 800) GT.EngineStart() s, _ := Graphics.NewBasicScene() g := TestGame{BaseScene: &s} // 500 sprites does about 38 fps on my laptop for i := 0; i < 500; i++ { nodebak := Components.NewNode("Person") nodebak.Transform().Translate(400, 400, 0) node := Components.NewNode("Person2") node.Transform().Translate(100, 100, 0) node.AddNode(nodebak) rend := Components.NewSpriteRenderer() rend.SetImage(GT.AssetsImages + "test.png") nodebak.Transform().Rotate(20, 0, 0, 1) nodebak.AddComponent(rend) rend2 := Components.NewSpriteRenderer() rend2.SetSubImage(GT.AssetsImages+"smiley.png", image.Rectangle{image.Point{30, 30}, image.Point{50, 50}}) nodebak2 := Components.NewNode("Person") nodebak2.Transform().Translate(50, 50, 0) nodebak2.AddComponent(rend2) // sr := nodebak2.GetComponent("SpriteRenderer") // fmt.Println(sr) node.AddNode(nodebak2) g.BaseScene.RootNode.AddNode(node) } g.Start() }
func main() { fmt.Println("starting") GT.EngineStart() s, _ := Graphics.NewBasicScene() nodebak := Components.NewNode("Person") nodebak.Transform().Translate(100, 100) node := Components.NewNode("Person2") textRend := Components.NewTextRenderer() textRend.SetFont("Raleway") textRend.SetText("Hello World From GT!?") textRend.SetSize(14) textRend.SetColor(1, .2, .1, 1) node.Transform().Translate(150, 100) textRend2 := Components.NewTextRenderer() textRend2.SetFont("Fantasque Sans Mono Regular") textRend2.SetSize(60) textRend2.SetText("This is Second Font Fantasque Bold") rend := Components.NewSpriteRenderer() rend.SetImage(GT.AssetsImages + "test.png") nodebak.Transform().Scale(.5, .5) nodebak.Transform().Rotate(1.2) nodebak.AddComponent(rend) nodebak.AddComponent(textRend2) node.AddComponent(textRend) s.RootNode.AddNode(node) s.RootNode.AddNode(nodebak) s.Start() }