// Wrap returns a wrapper func that handles the conversion from native JavaScript *js.Object parameters // to the following types. // // It supports *js.Object (left unmodified), dom.Document, dom.Element, dom.Event, dom.HTMLElement, dom.Node. // // For other types, the input is assumed to be a JSON string which is then unmarshalled into that type. func Wrap(fn interface{}) func(...*js.Object) { v := reflect.ValueOf(fn) return func(args ...*js.Object) { in := make([]reflect.Value, v.Type().NumIn()) for i := range in { switch t := v.Type().In(i); t { // *js.Object is passed through. case typeOf((**js.Object)(nil)): in[i] = reflect.ValueOf(args[i]) // dom types are wrapped. case typeOf((*dom.Element)(nil)): in[i] = reflect.ValueOf(dom.Wrap(args[i])) case typeOf((*dom.Event)(nil)): in[i] = reflect.ValueOf(dom.WrapEvent(args[i])) // Unmarshal incoming encoded JSON into the Go type. default: p := reflect.New(t) err := json.Unmarshal([]byte(args[i].String()), p.Interface()) if err != nil { panic(err) } in[i] = reflect.Indirect(p) } } v.Call(in) } }
func main() { // setup // ops := pixi.NewRendererOptions() // ops.Transparent = true // render = pixi.AutoDetectRenderer(800, 600, ops) render.BackgroundColor = 0x070202 // transparent works first sprites.Position.Set(400, 300) renderSprit.Anchor.SetTo(0.5) renderSprit.Position.Set(400, 300) stage.AddChild(sprites) stage.AddChild(renderSprit) stage.Interactive = true stage.HitArea = pixi.NewRectangle(0, 0, 800, 600) // load loadSprites() dom.OnDOMContentLoaded(func() { el := dom.Wrap(render.View) dom.Body().AppendChild(el) stage.On(pixi.EventClick, func(ed *pixi.InteractionEvent) { println("EventClick", ed.Data.Global) }).On(pixi.EventMouseClick, func(ed *pixi.InteractionEvent) { println("EventMouseClick", ed.Data.Global) }).On(pixi.EventMouseUp, func(ed *pixi.InteractionEvent) { println("EventMouseUp", ed.Data.Global) }) run(0) }) }
func main() { dom.OnDOMContentLoaded(func() { el := dom.Wrap(renderer.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(animate) }) }
func run() { sprite.Anchor.SetTo(0.5) sprite.Position.SetTo(20) stage.AddChild(sprite) render.Render(stage) el := dom.Wrap(render.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(animate) }
func main() { renderer.BackgroundColor = 0xffffff stage.AddChild(tilingSprite) dom.OnDOMContentLoaded(func() { el := dom.Wrap(renderer.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(run) }) }
func main() { snake1 := newSnake() snake1.Position.Set(0, 120) snake2 := newSnake() snake2.Position.Set(120, 300) stage.AddChild(snake1, snake2) dom.OnDOMContentLoaded(func() { el := dom.Wrap(renderer.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(animate) }) }
func main() { if renderer.Type == pixi.RendererType.WEBGL { maggotNum = 1000 } rand.Seed(time.Now().UnixNano()) for i := 0; i < maggotNum; i++ { sprites.AddChild(newMaggot()) } stage.AddChild(sprites) dom.OnDOMContentLoaded(func() { el := dom.Wrap(renderer.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(animate) }) }
func main() { stage.Interactive = true stage.On(pixi.EventClick, handler) g := newBall() stage.AddChild(g) dom.OnDOMContentLoaded(func() { renderer = pixi.AutoDetectRenderer(dom.Window().InnerWidth, dom.Window().InnerHeight) renderer.BackgroundColor = 0xffffff stage.HitArea = pixi.NewRectangle(0, 0, renderer.Width, renderer.Height) v := dom.Wrap(renderer.View) v.Width = dom.Window().InnerWidth v.Height = dom.Window().InnerHeight dom.Body().AppendChild(v) raf.RequestAnimationFrame(run) }) }
func main() { stage.Interactive = true // stage.AddChild(ctx) stage.On(pixi.EventMouseMove, func(ed *pixi.InteractionEvent) { id := ed.Data makeParticles(id.Global.X, id.Global.Y, 4) }) dom.OnDOMContentLoaded(func() { dom.Body().Style.SetProperty("margin", "0") renderer = pixi.AutoDetectRenderer(dom.Window().InnerWidth, dom.Window().InnerHeight) v := dom.Wrap(renderer.View) v.Width = dom.Window().InnerWidth v.Height = dom.Window().InnerHeight dom.Body().AppendChild(v) raf.RequestAnimationFrame(run) }) }
func main() { txt := pixi.NewText("A Text Object will create a line or multiple lines of text. \nTo split a line you can use '\\n' in your text string, or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object.", js.M{ "font": "36px Arial bold italic", "fill": "#F7EDCA", "stroke": "#4a1850", "strokeThickness": 5, "dropShadow": true, "dropShadowColor": "#000000", "dropShadowAngle": math.Pi / 6, "dropShadowDistance": 6, "wordWrap": true, "wordWrapWidth": 500, }) txt.Anchor.SetTo(0) txt.Position.Set(20, 20) stage.AddChild(txt) renderer.BackgroundColor = 0x1099bb dom.OnDOMContentLoaded(func() { el := dom.Wrap(renderer.View) dom.Body().AppendChild(el) raf.RequestAnimationFrame(run) }) }