Пример #1
0
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()
}
Пример #2
0
func main() {

	fmt.Println("starting")
	GT.EngineStart()

	s, _ := Graphics.NewBasicScene()

	// create text rendering components
	textRend := Components.NewTextRenderer()
	textRend.SetFont("Raleway")
	textRend.SetText("Hello World From GT!?")
	textRend.SetSize(14)
	textRend.SetColor(1, .2, .1, 1)

	textRend2 := Components.NewTextRenderer()
	textRend2.SetFont("Fantasque Sans Mono Regular")
	textRend2.SetSize(60)
	textRend2.SetText("Hello World Pt.2")

	// create nodes for them so we can apply transformation
	node1 := Components.NewNode("Text1")
	node1.Transform().Translate(100, 100, 0)
	node1.AddComponent(textRend)

	node2 := Components.NewNode("Text2")
	node2.Transform().Rotate(.3, 0, 0, 1)
	node2.Transform().Translate(150, 150, 0)
	node2.AddComponent(textRend2)

	s.RootNode.AddNode(node1)
	s.RootNode.AddNode(node2)

	s.Start()

}
Пример #3
0
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()

}
Пример #4
0
func Test_window(t *testing.T) {
	w := Window.NewWindowedWindow("test", 800, 600)

	s, _ := Graphics.NewBasicScene("test.png", 800, 600)

	for {
		s.Draw()
		w.Refresh()
	}

	// // e := w.Open()

	// // if e != nil {
	// // 	t.Error("Window open failure: " + e.Error())
	// // }

	// // if w.isOpen() == false {
	// // 	t.Error("Window should be open but it's not")
	// // }

	// // if w.Width != 800 {
	// // 	t.Error("Window width should be 800")
	// // }

	// // if w.Height != 600 {
	// // 	t.Error("Window height should be 600")
	// // }

	// running := true

	// for running == true {

	// 	w.Refresh()

	// }

	w.Close()

	// if w.isOpen() == true {
	// 	t.Error("Window should be closed but it's not")
	// }

}
Пример #5
0
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()

}
Пример #6
0
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()

}
Пример #7
0
func Test_Graphics(t *testing.T) {

	w := Window.NewWindowedWindow("test", 800, 600)

	s, _ := Graphics.NewBasicScene("smiley.png", 800, 600)

	s.AddSprite("smiley", Graphics.NewImageSection(0, 0, 128, 128))
	s.GetSprite("smiley").SetPosition(100, 100)

	// var window *sdl.Window
	// var context sdl.GLContext
	var event sdl.Event
	var running bool
	// var err error

	running = true

	for running {
		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseMotionEvent:

				fmt.Println(string(t.Timestamp))
			}
		}
		w.Clear()
		s.Draw()
		w.Refresh()
	}

	// // e := w.Open()

	// // if e != nil {
	// // 	t.Error("Window open failure: " + e.Error())
	// // }

	// // if w.isOpen() == false {
	// // 	t.Error("Window should be open but it's not")
	// // }

	// // if w.Width != 800 {
	// // 	t.Error("Window width should be 800")
	// // }

	// // if w.Height != 600 {
	// // 	t.Error("Window height should be 600")
	// // }

	// running := true

	// for running == true {

	// 	w.Refresh()

	// }

	w.Close()

}
Пример #8
0
func main() {

	// defer profile.Start(profile.CPUProfile).Stop()
	w := Window.NewWindowedWindow("test", 600, 400)
	s, _ := Graphics.NewBasicScene("smiley.png", &w)
	g := TestGame{BaseScene: &s}

	g.LoadHandler = g.Load
	g.UpdateHandler = g.Update

	fmt.Println(g)
	// for i := 0; i < 25000; i++ {
	// s.AddSprite("smiley"+string(i), Graphics.NewImageSection(0, 0, 128, 128))
	// s.GetSprite("smiley"+string(i)).SetLocation(float32(0), float32(random(0, 500)))
	// _, y := s.GetSprite("smiley" + string(i)).GetLocation()
	// fmt.Printf("smileystart %d has y %f\n", i, y)
	// }

	// var window *sdl.Window
	// var context sdl.GLContext
	// var event sdl.Event
	// var running bool
	// var err error

	// running = true
	// // x := 0
	// for running {
	// 	for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
	// 		switch t := event.(type) {
	// 		case *sdl.QuitEvent:
	// 			running = false
	// 		case *sdl.MouseMotionEvent:

	// 			fmt.Println(string(t.Timestamp))
	// 		}
	// 	}
	// w.Clear()
	// for i := 0; i < 25000; i++ {
	// 	_, y := s.GetSprite("smiley" + string(i)).GetLocation()
	// 	s.GetSprite("smiley"+string(i)).SetLocation(float32(x), y)
	// 	// fmt.Printf("smileyend %d has y %f\n", i, y)
	// }
	// s.Draw()
	// w.Refresh()

	g.Start()

	// x += 1
	// }

	// // e := w.Open()

	// // if e != nil {
	// //   t.Error("Window open failure: " + e.Error())
	// // }

	// // if w.isOpen() == false {
	// //   t.Error("Window should be open but it's not")
	// // }

	// // if w.Width != 800 {
	// //   t.Error("Window width should be 800")
	// // }

	// // if w.Height != 600 {
	// //   t.Error("Window height should be 600")
	// // }

	// running := true

	// for running == true {

	//  w.Refresh()

	// }

	w.Close()

}