func NewButton(x, y float64, upTex, downTex, overTex *pixi.Texture) *Button { sprite := pixi.NewSprite(upTex) sprite.ButtonMode = true sprite.Anchor.SetTo(0.5) sprite.Position.Set(x, y) sprite.Interactive = true button := &Button{ Sprite: sprite, isDown: false, isOver: false, upTex: upTex, downTex: downTex, overTex: overTex, } button.On(pixi.EventMouseUp, func(ed *pixi.InteractionEvent) { button.up(ed.Data) }) button.On(pixi.EventTouchEnd, func(ed *pixi.InteractionEvent) { button.up(ed.Data) }) button.On(pixi.EventMouseUpOutside, func(ed *pixi.InteractionEvent) { button.up(ed.Data) }) button.On(pixi.EventTouchEndOutside, func(ed *pixi.InteractionEvent) { button.up(ed.Data) }) button.On(pixi.EventMouseDown, func(ed *pixi.InteractionEvent) { button.down(ed.Data) }) button.On(pixi.EventTouchStart, func(ed *pixi.InteractionEvent) { button.down(ed.Data) }) button.On(pixi.EventMouseOver, func(ed *pixi.InteractionEvent) { button.over(ed.Data) }) button.On(pixi.EventMouseOut, func(ed *pixi.InteractionEvent) { button.out(ed.Data) }) return button }
func main() { js.Global.Get("document").Get("body").Call("appendChild", renderer.View) rand.Seed(int64(time.Now().Nanosecond())) sx = 1.0 + rand.Float64()/20 sy = 1.0 + rand.Float64()/20 for i := 0; i < 2500; i++ { ball := pixi.NewSprite(texture) ball.Position.Set(rand.Float64()*width-slideX, rand.Float64()*height-slideY) ball.Anchor.SetTo(0.5) balls = append(balls, &Ball{ball, ball.Position.X, ball.Position.Y}) stage.AddChild(ball) } raf.RequestAnimationFrame(animate) }
import ( "github.com/Archs/js/dom" "github.com/Archs/js/raf" "github.com/Archs/pixi" "math" "math/rand" ) var ( stage = pixi.NewContainer() sprites = pixi.NewContainer() render = pixi.AutoDetectRenderer(800, 600) renderTexture = pixi.NewRenderTexture(render, render.Width, render.Height, pixi.ScaleModes.Default, 1) renderTexture2 = pixi.NewRenderTexture(render, render.Width, render.Height, pixi.ScaleModes.Default, 1) renderSprit = pixi.NewSprite(renderTexture.Texture) count = 0.0 ) var fruits = []string{ "assets/spinObj_01.png", "assets/spinObj_02.png", "assets/spinObj_03.png", "assets/spinObj_04.png", "assets/spinObj_05.png", "assets/spinObj_06.png", "assets/spinObj_07.png", "assets/spinObj_08.png", }
package main import ( "github.com/Archs/js/raf" "github.com/Archs/pixi" "github.com/gopherjs/gopherjs/js" ) var ( stage = pixi.NewContainer() renderer = pixi.AutoDetectRenderer(400, 300) texture = pixi.TextureFromImage("bunny.png", true, pixi.ScaleModes.Default) bunny = pixi.NewSprite(texture) ) func animate(t float64) { raf.RequestAnimationFrame(animate) bunny.Rotation += 0.1 renderer.Render(stage) } func main() { js.Global.Get("document").Get("body").Call("appendChild", renderer.View) renderer.BackgroundColor = 0x66FF99 bunny.Anchor.SetTo(0.5) bunny.Position.Set(200, 150) stage.AddChild(bunny) raf.RequestAnimationFrame(animate)