예제 #1
0
파일: main.go 프로젝트: govlas/pixi
func newFruit(url string) *Fruit {
	f := new(Fruit)
	f.url = url
	f.Sprite = pixi.SpriteFromImage(f.url, false, pixi.ScaleModes.Default)
	f.Anchor.SetTo(0.5)
	f.Position.X = rand.Float64()*400 - 200
	f.Position.Y = rand.Float64()*400 - 200
	f.Update = f.update
	return f
}
예제 #2
0
파일: main.go 프로젝트: govlas/pixi
func newMaggot() *Maggot {
	s := new(Maggot)
	s.Sprite = pixi.SpriteFromImage("img/tinyMaggot.png", false, pixi.ScaleModes.Default)
	s.direction = 2 * math.Pi * rand.Float64()
	s.Rotation = math.Pi - s.direction
	s.Scale.SetTo(0.4)
	s.Anchor.SetTo(0.5)
	s.Position.X = renderer.Width * rand.Float64()
	s.Position.Y = renderer.Height * rand.Float64()
	s.step = 2 + 5*rand.Float64()
	s.Update = s.run
	return s
}
예제 #3
0
파일: main.go 프로젝트: govlas/pixi
func NewDraggableSprite(url string, x, y float64) *DraggableSprite {
	sprite := pixi.SpriteFromImage(url, false, pixi.ScaleModes.Nearest)

	sprite.Interactive = true
	sprite.ButtonMode = true
	sprite.Position.Set(x, y)
	sprite.Anchor.SetTo(0.5)
	sprite.Scale.SetTo(3)

	ds := &DraggableSprite{Sprite: sprite}

	ds.On(pixi.EventMouseDown, func(ed *pixi.InteractionEvent) { ds.down(ed.Data) })
	ds.On(pixi.EventTouchStart, func(ed *pixi.InteractionEvent) { ds.down(ed.Data) })

	ds.On(pixi.EventMouseUp, func(ed *pixi.InteractionEvent) { ds.up(ed.Data) })
	ds.On(pixi.EventMouseUpOutside, func(ed *pixi.InteractionEvent) { ds.up(ed.Data) })
	ds.On(pixi.EventTouchEnd, func(ed *pixi.InteractionEvent) { ds.up(ed.Data) })
	ds.On(pixi.EventTouchEndOutside, func(ed *pixi.InteractionEvent) { ds.up(ed.Data) })

	ds.On(pixi.EventMouseMove, func(ed *pixi.InteractionEvent) { ds.move(ed.Data) })

	return ds
}
예제 #4
0
파일: main.go 프로젝트: govlas/pixi
package main

import (
	"github.com/Archs/js/raf"
	"github.com/Archs/pixi"

	"github.com/gopherjs/gopherjs/js"
)

var (
	stage      = pixi.NewContainer()
	renderer   = pixi.AutoDetectRenderer(620, 400)
	background = pixi.SpriteFromImage("bg.jpg", true, pixi.ScaleModes.Default)
	buttons    = make([]*Button, 0)
)

type Button struct {
	*pixi.Sprite
	isDown  bool
	isOver  bool
	upTex   *pixi.Texture
	downTex *pixi.Texture
	overTex *pixi.Texture
}

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)
예제 #5
0
파일: main.go 프로젝트: govlas/pixi
package main

import (
	"github.com/Archs/js/dom"
	"github.com/Archs/js/raf"
	"github.com/Archs/pixi"
	_ "github.com/Archs/pixi/shim"
	"math"
	"math/rand"
)

var (
	stage    = pixi.NewContainer()
	render   *pixi.Renderer
	sprite   = pixi.SpriteFromImage("img/bunny.png", false, pixi.ScaleModes.Default)
	lastTime = float64(0)
	stepX    = float64(5)
	stepY    = float64(3)
	counter  = 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
	}