Пример #1
0
func main() {
	js.Global.Get("document").Get("body").Call("appendChild", renderer.View)
	renderer.BackgroundColor = 0x97C56E
	stage.AddChild(NewDraggableSprite("bunny.png", 400, 300))

	raf.RequestAnimationFrame(animate)
}
Пример #2
0
func main() {
	js.Global.Get("document").Get("body").Call("appendChild", renderer.View)

	stage.AddChild(background)

	upTex := pixi.TextureFromImage("buttonUp.png", true, pixi.ScaleModes.Default)
	downTex := pixi.TextureFromImage("buttonDown.png", true, pixi.ScaleModes.Default)
	overTex := pixi.TextureFromImage("buttonOver.png", true, pixi.ScaleModes.Default)

	coords := []float64{
		175.0, 75.0,
		600 - 145, 75,
		600/2 - 20, 400/2 + 10,
		175, 400 - 75,
		600 - 115, 400 - 95,
	}

	for i := 0; i < len(coords)/2; i++ {
		button := NewButton(coords[i*2], coords[i*2+1], upTex, downTex, overTex)
		stage.AddChild(button)
		buttons = append(buttons, button)
	}

	buttons[0].Scale.X = 1.2
	buttons[1].Scale.Y = 1.2
	buttons[2].Rotation = 0.314159
	buttons[3].Scale.SetTo(0.8)
	buttons[4].Scale.Set(0.8, 1.2)
	buttons[4].Rotation = 3.14159

	raf.RequestAnimationFrame(animate)
}
Пример #3
0
func main() {
	dom.OnDOMContentLoaded(func() {
		el := dom.Wrap(renderer.View)
		dom.Body().AppendChild(el)
		raf.RequestAnimationFrame(animate)
	})
}
Пример #4
0
func run(t float64) {
	for _, b := range bs {
		b.draw(t)
	}
	renderer.Render(stage)
	raf.RequestAnimationFrame(run)
}
Пример #5
0
func animate(t float64) {
	raf.RequestAnimationFrame(animate)
	for _, s := range sprites.Children {
		s.Update(t)
	}
	renderer.Render(stage)
}
Пример #6
0
func animate(t float64) {
	raf.RequestAnimationFrame(animate)
	for _, s := range stage.Children {
		s.Update(t)
	}
	// move the snake
	renderer.Render(stage)
}
Пример #7
0
func run(t float64) {
	counter += 0.05
	raf.RequestAnimationFrame(run)
	tilingSprite.TileScale.Set(math.Sin(counter)+2, math.Cos(counter)+2)
	tilingSprite.TilePosition.X += 1
	tilingSprite.TilePosition.Y += 1
	renderer.Render(stage)
}
Пример #8
0
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)
}
Пример #9
0
func main() {
	renderer.BackgroundColor = 0xffffff
	stage.AddChild(tilingSprite)
	dom.OnDOMContentLoaded(func() {
		el := dom.Wrap(renderer.View)
		dom.Body().AppendChild(el)
		raf.RequestAnimationFrame(run)
	})
}
Пример #10
0
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)
}
Пример #11
0
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)
	})
}
Пример #12
0
func animate(t float64) {
	for i := 0; i < len(aliens); i++ {
		aliens[i].Rotation += 0.1
	}

	count += 0.01
	group.Scale.X = math.Sin(count)
	group.Scale.Y = math.Sin(count)
	group.Rotation += 0.01

	renderer.Render(stage)
	raf.RequestAnimationFrame(animate)
}
Пример #13
0
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)
	})
}
Пример #14
0
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)
	})
}
Пример #15
0
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)
	})
}
Пример #16
0
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)
}
Пример #17
0
func animate(t float64) {
	defer raf.RequestAnimationFrame(animate)
	counter += 1
	if counter%2 != 0 {
		return
	}
	// println(counter, sprite.Position.X, sprite.Position.Y)
	if sprite.Position.X >= 290 || sprite.Position.X <= 10 {
		stepX = -1 * stepX
	}
	if sprite.Position.Y >= 290 || sprite.Position.Y <= 10 {
		stepY = -1 * stepY
	}
	sprite.Position.Set(sprite.Position.X+rand.Float64()*stepX,
		sprite.Position.Y+rand.Float64()*stepY)
	sprite.Rotation = math.Mod(t/100, 2*math.Pi)
	render.Render(stage)
}
Пример #18
0
func run(t float64) {
	raf.RequestAnimationFrame(run)
	counter += 1
	// frame control
	if counter%2 == 0 {
		return
	}
	// update & draw all the particles
	ctx.ClearRect(0, 0, cw, ch)
	for i := len(ps) - 1; i >= 0; i-- {
		p := ps[i]
		p.update()
		if !p.isAlive() {
			ps = append(ps[:i], ps[i+1:]...)
		} else {
			p.draw(t)
		}
	}
}
Пример #19
0
func run(t float64) {
	count += 0.01
	defer raf.RequestAnimationFrame(run)
	for _, s := range sprites.Children {
		s.Update(t)
	}

	temp := renderTexture
	renderTexture = renderTexture2
	renderTexture2 = temp
	// set the new texture
	renderSprit.Texture = renderTexture.Texture
	// twist this up!
	sprites.Rotation -= 0.01
	renderSprit.Scale.SetTo(1 + math.Sin(count)*0.2)
	renderTexture2.Render(stage, false, true)
	// and finally render the stage
	render.Render(stage)
}
Пример #20
0
func onAssetsLoaded() {
	textures := make([]*pixi.Texture, 0)
	for i := 0; i < 26; i++ {
		frame := fmt.Sprintf("Explosion_Sequence_A %d.png", i+1)
		textures = append(textures, pixi.TextureFromFrame(frame))
	}

	for i := 0; i < 50; i++ {
		explosion := pixi.NewMovieClip(textures)
		explosion.Position.Set(rand.Float64()*800, rand.Float64()*600)
		explosion.Anchor.SetTo(0.5)
		explosion.Rotation = rand.Float64() * math.Pi
		explosion.Scale.SetTo(0.75 + rand.Float64()*0.5)
		explosion.GotoAndPlay(rand.Int() % 27)
		stage.AddChild(explosion)
	}

	raf.RequestAnimationFrame(animate)
}
Пример #21
0
func onAssetsLoaded() {
	frames := []string{
		"eggHead.png",
		"flowerTop.png",
		"helmlok.png",
		"skully.png",
	}

	for i := 0; i < 100; i++ {
		alien := pixi.SpriteFromFrame(frames[i%4])
		alien.Tint = rand.Uint32()
		alien.Position.X = rand.Float64()*800 - 400
		alien.Position.Y = rand.Float64()*600 - 300
		alien.Anchor.SetTo(0.5)
		aliens = append(aliens, alien)
		group.AddChild(alien)
	}

	raf.RequestAnimationFrame(animate)
}
Пример #22
0
func run(t float64) {
	raf.RequestAnimationFrame(run)
	counter += 1
	// frame control
	if counter%2 == 0 {
		return
	}
	// update & draw all the particles
	// ctx.Clear()
	for i := len(ps) - 1; i >= 0; i-- {
		p := ps[i]
		p.update()
		if !p.isAlive() {
			ps = append(ps[:i], ps[i+1:]...)
			stage.RemoveChild(p)
		} else {
			p.draw(t)
		}
	}
	renderer.Render(stage)
}
Пример #23
0
func main() {
	dom.OnDOMContentLoaded(func() {
		s := dom.GetElementById("gopherjs")
		style := dom.GetComputedStyle(s)

		el := canvas.New(dom.CreateElement("canvas").Object)
		cw, _ = strconv.ParseFloat(style.GetPropertyValue("width")[:3], 64)
		ch, _ = strconv.ParseFloat(style.GetPropertyValue("height")[:3], 64)
		el.Width = int(cw)
		el.Height = int(ch)
		el.AddEventListener(dom.EvtMousemove, func(e *dom.Event) {
			e.PreventDefault()
			x := float64(e.LayerX)
			y := float64(e.LayerY)
			makeParticles(x, y, 5)
		})
		ctx = el.GetContext2D()
		ctx.GlobalCompositeOperation = canvas.CompositeLighter
		s.AppendChild(el.Element)
		raf.RequestAnimationFrame(run)
	})
}
Пример #24
0
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)
	})
}
Пример #25
0
func animate(t float64) {
	for i := 0; i < len(balls); i++ {
		ball := balls[i]
		ball.sprite.Position.X = ball.x + slideX
		ball.sprite.Position.Y = ball.y + slideY
		ball.x *= sx
		ball.y *= sy

		if ball.x > width {
			ball.x -= width
		} else if ball.x < -width {
			ball.x += width
		}

		if ball.y > height {
			ball.y -= height
		} else if ball.y < -height {
			ball.y += height
		}
	}

	renderer.Render(stage)
	raf.RequestAnimationFrame(animate)
}
Пример #26
0
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)
	})
}
Пример #27
0
func run(t float64) {
	raf.RequestAnimationFrame(run)
	renderer.Render(stage)
}
Пример #28
0
func animate(t float64) {
	raf.RequestAnimationFrame(animate)
	renderer.Render(stage)
}
Пример #29
0
func animate(t float64) {
	raf.RequestAnimationFrame(animate)
	bunny.Rotation += 0.1
	renderer.Render(stage)
}