本文整理匯總了Golang中github.com/paked/engi/ecs.Entity.AddComponent方法的典型用法代碼示例。如果您正苦於以下問題:Golang Entity.AddComponent方法的具體用法?Golang Entity.AddComponent怎麽用?Golang Entity.AddComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/paked/engi/ecs.Entity
的用法示例。
在下文中一共展示了Entity.AddComponent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Update
func (c *Calibrate) Update(entity *ecs.Entity, dt float32) {
if c.frameIndex != 0 {
return
}
var (
cal *CalibrateComponent
ok bool
)
if cal, ok = entity.ComponentFast(cal).(*CalibrateComponent); !ok {
return
}
// Render the image again
plt, err := plot.New()
if err != nil {
log.Fatal(err)
}
plotutil.AddLinePoints(plt,
"CH"+strconv.Itoa(int(cal.ChannelIndex)), plotter.XYer(c.channels[cal.ChannelIndex]))
img := image.NewRGBA(image.Rect(0, 0, 3*dpi, 3*dpi))
canv := vgimg.NewWith(vgimg.UseImage(img))
plt.Draw(draw.New(canv))
bgTexture := engi.NewImageRGBA(img)
// Give it to engi
erender := &engi.RenderComponent{
Display: engi.NewRegion(engi.NewTexture(bgTexture), 0, 0, 3*dpi, 3*dpi),
Scale: engi.Point{1, 1},
Transparency: 1,
Color: color.RGBA{255, 255, 255, 255},
}
erender.SetPriority(engi.HUDGround)
entity.AddComponent(erender)
}
示例2: Update
func (m *Maze) Update(entity *ecs.Entity, dt float32) {
if entity.ID() != m.playerEntity.ID() {
return
}
var (
move *MovementComponent
ok bool
)
if move, ok = entity.ComponentFast(move).(*MovementComponent); ok {
return // because we're still moving!
}
if m.currentLevel.Width == 0 || m.currentLevel.Height == 0 {
return // because there's no maze
}
oldX, oldY := m.currentLevel.PlayerX, m.currentLevel.PlayerY
if m.currentLevel.Grid[oldY][oldX] == TileGoal {
// Goal achieved!
if strings.HasPrefix(m.currentLevel.Name, "Random ") {
engi.Mailbox.Dispatch(MazeMessage{})
return
}
if m.sequence != SequenceNone {
m.cleanup()
m.initialize("")
return
}
}
switch m.Controller.Action(m.currentLevel) {
case ActionUp:
m.currentLevel.PlayerY--
case ActionDown:
m.currentLevel.PlayerY++
case ActionLeft:
m.currentLevel.PlayerX--
case ActionRight:
m.currentLevel.PlayerX++
case ActionStop:
return // so don't move
}
if !m.currentLevel.IsAvailable(m.currentLevel.PlayerX, m.currentLevel.PlayerY) {
m.currentLevel.PlayerX, m.currentLevel.PlayerY = oldX, oldY
return // because it's an invalid move
}
entity.AddComponent(&MovementComponent{
From: engi.Point{float32(oldX) * tileWidth, float32(oldY) * tileHeight},
To: engi.Point{float32(m.currentLevel.PlayerX) * tileWidth, float32(m.currentLevel.PlayerY) * tileHeight},
In: time.Second / moveSpeed,
Callback: func() {
if m.currentLevel.Grid[m.currentLevel.PlayerY][m.currentLevel.PlayerX] == TileRoute {
m.currentLevel.Grid[m.currentLevel.PlayerY][m.currentLevel.PlayerX] = TileBlank
m.currentLevel.GridEntities[m.currentLevel.PlayerY][m.currentLevel.PlayerX].AddComponent(tileBlank)
} else if m.currentLevel.Grid[oldY][oldX] == TileError ||
m.currentLevel.Grid[oldY][oldX] == TileBlank {
m.currentLevel.Grid[oldY][oldX] = TileRoute
if m.currentLevel.Grid[m.currentLevel.PlayerY][m.currentLevel.PlayerX] == TileHiddenError {
m.currentLevel.Grid[m.currentLevel.PlayerY][m.currentLevel.PlayerX] = TileError
}
}
},
})
}