Example #1
0
File: test.go Project: theclapp/js
func test() {
	body := dom.Body()
	div := dom.Document().CreateElement("div")
	div.SetAttribute("id", "div")
	div.SetAttribute("class", "div")
	body.AppendChild(div)
	body.SetAttribute("aaa", 123)
	// println("getAttr", body.GetAttribute)
	println(body.GetAttribute("aaa"))
	// println("Object:", body.Object)
	// println("Body:", body)
	// println("GetElementsByTagName", body.GetElementsByTagName)
	c := body.GetElementsByTagName("div")
	println(c)
	el := c.Item(0)
	println(el.GetAttribute("id"))

	el = body.QuerySelector("div")
	println(el.GetAttribute("id"))
	c = body.QuerySelectorAll("div")
	println(c, c.Length, c.Item(0).GetAttribute("id"))
	println("el:", el)
	el.Style.SetProperty("width", "100")
	el.Style.SetProperty("height", "100")
	el.Style.SetProperty("border", "dotted")
	el.AddEventListener(dom.EvtClick, func(e *dom.Event) {
		println("click:", e, e.ClientX, e.ClientY, e.ScreenX, e.ClientY)
		println("CurrentTarget", e.CurrentTarget)
	})
}
Example #2
0
File: main.go Project: govlas/pixi
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)
	})
}
Example #3
0
File: main.go Project: govlas/pixi
func main() {
	dom.OnDOMContentLoaded(func() {
		el := dom.Wrap(renderer.View)
		dom.Body().AppendChild(el)
		raf.RequestAnimationFrame(animate)
	})
}
Example #4
0
File: main.go Project: govlas/pixi
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)
	})
}
Example #5
0
File: main.go Project: govlas/pixi
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)
}
Example #6
0
File: main.go Project: govlas/pixi
func main() {
	renderer.BackgroundColor = 0xffffff
	stage.AddChild(tilingSprite)
	dom.OnDOMContentLoaded(func() {
		el := dom.Wrap(renderer.View)
		dom.Body().AppendChild(el)
		raf.RequestAnimationFrame(run)
	})
}
Example #7
0
File: ko.go Project: theclapp/js
// RegisterComponent is used to create KnockoutJS component with more options
func RegisterComponent(c *Component) {
	if c.Style != "" {
		style := dom.Document().CreateElement("style")
		style.InnerHTML = c.Style
		dom.Body().AppendChild(style)
	}
	rawRegisterComponent(c.Name, js.M{
		"template":    c.template(),
		"viewModel":   c.viewModel(),
		"synchronous": c.Synchronous,
	})
}
Example #8
0
File: main.go Project: govlas/pixi
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)
	})
}
Example #9
0
File: main.go Project: govlas/pixi
func main() {
	dom.OnDOMContentLoaded(func() {
		s := dom.Body()
		// set full window and black background
		s.Style.SetProperty("margin", "0")
		s.Style.SetProperty("background", "#222")

		el := canvas.New(dom.CreateElement("canvas").Object)
		cw = float64(dom.Window().InnerWidth)
		ch = float64(dom.Window().InnerHeight)
		el.Width = int(cw)
		el.Height = int(ch)
		el.AddEventListener(dom.EvtMousemove, func(e *dom.Event) {
			e.PreventDefault()
			x := float64(e.ClientX)
			y := float64(e.ClientY)
			makeParticles(x, y, 5)
		})
		ctx = el.GetContext2D()
		ctx.GlobalCompositeOperation = canvas.CompositeLighter
		dom.Body().AppendChild(el.Element)
		raf.RequestAnimationFrame(run)
	})
}
Example #10
0
File: main.go Project: govlas/pixi
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)
	})
}
Example #11
0
File: main.go Project: govlas/pixi
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)
	})
}
Example #12
0
File: main.go Project: govlas/pixi
func main() {
	ops := pixi.NewRendererOptions()
	ops.Transparent = true
	render = pixi.AutoDetectRenderer(300, 300, ops)
	stage.Interactive = true
	stage.HitArea = pixi.NewRectangle(0, 0, 300, 300)
	render.BackgroundColor = 0xff0000 // transparent works first
	render.Transparent = true
	dom.OnDOMContentLoaded(func() {
		dom.Body().Style.SetProperty("background", "blue")
		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()
	})
}
Example #13
0
File: main.go Project: govlas/pixi
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)
	})
}