本文整理汇总了Golang中github.com/paked/engi/ecs.Entity.RemoveComponent方法的典型用法代码示例。如果您正苦于以下问题:Golang Entity.RemoveComponent方法的具体用法?Golang Entity.RemoveComponent怎么用?Golang Entity.RemoveComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/paked/engi/ecs.Entity
的用法示例。
在下文中一共展示了Entity.RemoveComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Update
func (a *MovementSystem) Update(entity *ecs.Entity, dt float32) {
var move *MovementComponent
if !entity.Component(&move) {
return
}
if !move.started {
move.started = true
move.timeLeft = float32(move.In.Seconds())
move.speedX = (move.From.X - move.To.X) / move.timeLeft
move.speedY = (move.From.Y - move.To.Y) / move.timeLeft
}
move.timeLeft -= dt
var space *engi.SpaceComponent
if !entity.Component(&space) {
return
}
space.Position.X -= move.speedX * dt
space.Position.Y -= move.speedY * dt
if move.timeLeft < 0 {
// Because we might move more than needed
space.Position.X -= move.speedX * move.timeLeft
space.Position.Y -= move.speedY * move.timeLeft
move.timeLeft = 0
}
if move.timeLeft == 0 {
entity.RemoveComponent(move)
move.Callback()
}
}
示例2: Update
func (as *AudioSystem) Update(entity *ecs.Entity, dt float32) {
var ac *AudioComponent
var ok bool
if ac, ok = entity.ComponentFast(ac).(*AudioComponent); !ok {
return
}
if ac.player == nil {
f := Files.Sound(ac.File)
if f == nil {
return
}
var err error
ac.player, err = NewPlayer(f, 0, 0)
if err != nil {
log.Println("Error initializing AudioSystem:", err)
return
}
}
if ac.player.State() != Playing {
if ac.player.State() == Stopped {
if !ac.Repeat {
al.RewindSources(ac.player.source)
al.StopSources(ac.player.source)
entity.RemoveComponent(ac)
return
}
}
// Prepares if the track hasn't been buffered before.
if err := ac.player.prepare(ac.Background, 0, false); err != nil {
log.Println("Error initializing AudioSystem:", err)
return
}
al.PlaySources(ac.player.source)
if !ac.Background {
var space *SpaceComponent
var ok bool
if space, ok = entity.ComponentFast(space).(*SpaceComponent); !ok {
return
}
ac.player.source.SetPosition(al.Vector{
(space.Position.X + space.Width/2) / Width(),
(space.Position.Y + space.Height/2) / Height(),
0})
}
}
}