本文整理汇总了Golang中github.com/paked/engi.NewRenderComponent函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRenderComponent函数的具体用法?Golang NewRenderComponent怎么用?Golang NewRenderComponent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRenderComponent函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Setup
func (pong *PongGame) Setup(w *ecs.World) {
engi.SetBg(0x2d3739)
w.AddSystem(&engi.RenderSystem{})
w.AddSystem(&engi.CollisionSystem{})
w.AddSystem(&SpeedSystem{})
w.AddSystem(&ControlSystem{})
w.AddSystem(&BallSystem{})
w.AddSystem(&ScoreSystem{})
basicFont = (&engi.Font{URL: "Roboto-Regular.ttf", Size: 32, FG: color.NRGBA{255, 255, 255, 255}})
if err := basicFont.CreatePreloaded(); err != nil {
log.Fatalln("Could not load font:", err)
}
ball := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "SpeedSystem", "BallSystem"})
ballTexture := engi.Files.Image("ball.png")
ballRender := engi.NewRenderComponent(ballTexture, engi.Point{2, 2}, "ball")
ballSpace := &engi.SpaceComponent{engi.Point{(engi.Width() - ballTexture.Width()) / 2, (engi.Height() - ballTexture.Height()) / 2}, ballTexture.Width() * ballRender.Scale().X, ballTexture.Height() * ballRender.Scale().Y}
ballCollision := &engi.CollisionComponent{Main: true, Solid: true}
ballSpeed := &SpeedComponent{}
ballSpeed.Point = engi.Point{300, 100}
ball.AddComponent(ballRender)
ball.AddComponent(ballSpace)
ball.AddComponent(ballCollision)
ball.AddComponent(ballSpeed)
w.AddEntity(ball)
score := ecs.NewEntity([]string{"RenderSystem", "ScoreSystem"})
scoreRender := engi.NewRenderComponent(basicFont.Render(" "), engi.Point{1, 1}, "YOLO <3")
scoreSpace := &engi.SpaceComponent{engi.Point{100, 100}, 100, 100}
score.AddComponent(scoreRender)
score.AddComponent(scoreSpace)
w.AddEntity(score)
schemes := []string{"WASD", ""}
for i := 0; i < 2; i++ {
paddle := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "ControlSystem"})
paddleTexture := engi.Files.Image("paddle.png")
paddleRender := engi.NewRenderComponent(paddleTexture, engi.Point{2, 2}, "paddle")
x := float32(0)
if i != 0 {
x = 800 - 16
}
paddleSpace := &engi.SpaceComponent{engi.Point{x, (engi.Height() - paddleTexture.Height()) / 2}, paddleRender.Scale().X * paddleTexture.Width(), paddleRender.Scale().Y * paddleTexture.Height()}
paddleControl := &ControlComponent{schemes[i]}
paddleCollision := &engi.CollisionComponent{Main: false, Solid: true}
paddle.AddComponent(paddleRender)
paddle.AddComponent(paddleSpace)
paddle.AddComponent(paddleControl)
paddle.AddComponent(paddleCollision)
w.AddEntity(paddle)
}
}
示例2: Setup
func (pong *PongGame) Setup(w *engi.World) {
engi.SetBg(0x2d3739)
w.AddSystem(&engi.RenderSystem{})
w.AddSystem(&engi.CollisionSystem{})
w.AddSystem(&SpeedSystem{})
w.AddSystem(&ControlSystem{})
w.AddSystem(&BallSystem{})
w.AddSystem(&ScoreSystem{})
ball := engi.NewEntity([]string{"RenderSystem", "CollisionSystem", "SpeedSystem", "BallSystem"})
ballTexture := engi.Files.Image("ball.png")
ballRender := engi.NewRenderComponent(ballTexture, engi.Point{2, 2}, "ball")
ballSpace := &engi.SpaceComponent{engi.Point{(engi.Width() - ballTexture.Width()) / 2, (engi.Height() - ballTexture.Height()) / 2}, ballTexture.Width() * ballRender.Scale.X, ballTexture.Height() * ballRender.Scale.Y}
ballCollision := &engi.CollisionComponent{Main: true, Solid: true}
ballSpeed := &SpeedComponent{}
ballSpeed.Point = engi.Point{300, 100}
ball.AddComponent(ballRender)
ball.AddComponent(ballSpace)
ball.AddComponent(ballCollision)
ball.AddComponent(ballSpeed)
w.AddEntity(ball)
score := engi.NewEntity([]string{"RenderSystem", "ScoreSystem"})
scoreRender := engi.NewRenderComponent(basicFont.Render(" "), engi.Point{1, 1}, "YOLO <3")
scoreSpace := &engi.SpaceComponent{engi.Point{100, 100}, 100, 100}
score.AddComponent(scoreRender)
score.AddComponent(scoreSpace)
w.AddEntity(score)
schemes := []string{"WASD", ""}
for i := 0; i < 2; i++ {
paddle := engi.NewEntity([]string{"RenderSystem", "CollisionSystem", "ControlSystem"})
paddleTexture := engi.Files.Image("paddle.png")
paddleRender := engi.NewRenderComponent(paddleTexture, engi.Point{2, 2}, "paddle")
x := float32(0)
if i != 0 {
x = 800 - 16
}
paddleSpace := &engi.SpaceComponent{engi.Point{x, (engi.Height() - paddleTexture.Height()) / 2}, paddleRender.Scale.X * paddleTexture.Width(), paddleRender.Scale.Y * paddleTexture.Height()}
paddleControl := &ControlComponent{schemes[i]}
paddleCollision := &engi.CollisionComponent{Main: false, Solid: true}
paddle.AddComponent(paddleRender)
paddle.AddComponent(paddleSpace)
paddle.AddComponent(paddleControl)
paddle.AddComponent(paddleCollision)
w.AddEntity(paddle)
}
}
示例3: generateBackground
// generateBackground creates a background of green tiles - might not be the most efficient way to do this
func generateBackground() *ecs.Entity {
rect := image.Rect(0, 0, int(worldWidth), int(worldHeight))
img := image.NewNRGBA(rect)
c1 := color.RGBA{102, 153, 0, 255}
c2 := color.RGBA{102, 173, 0, 255}
for i := rect.Min.X; i < rect.Max.X; i++ {
for j := rect.Min.Y; j < rect.Max.Y; j++ {
if i%40 > 20 {
if j%40 > 20 {
img.Set(i, j, c1)
} else {
img.Set(i, j, c2)
}
} else {
if j%40 > 20 {
img.Set(i, j, c2)
} else {
img.Set(i, j, c1)
}
}
}
}
bgTexture := engi.NewImageObject(img)
field := ecs.NewEntity([]string{"RenderSystem"})
fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "Background1")
fieldRender.SetPriority(engi.Background)
fieldSpace := &engi.SpaceComponent{engi.Point{0, 0}, worldWidth, worldHeight}
field.AddComponent(fieldRender)
field.AddComponent(fieldSpace)
return field
}
示例4: Setup
func (game *Game) Setup(w *engi.World) {
engi.SetBg(0x2d3739)
// Add all of the systems
w.AddSystem(&engi.RenderSystem{})
w.AddSystem(&engi.CollisionSystem{})
w.AddSystem(&DeathSystem{})
w.AddSystem(&FallingSystem{})
w.AddSystem(&ControlSystem{})
w.AddSystem(&RockSpawnSystem{})
// Create new entity subscribed to all the systems!
guy := engi.NewEntity([]string{"RenderSystem", "ControlSystem", "RockSpawnSystem", "CollisionSystem", "DeathSystem"})
texture := engi.Files.Image("icon.png")
render := engi.NewRenderComponent(texture, engi.Point{4, 4}, "guy")
// Tell the collision system that this player is solid
collision := &engi.CollisionComponent{Solid: true, Main: true}
width := texture.Width() * render.Scale.X
height := texture.Height() * render.Scale.Y
space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}
guy.AddComponent(render)
guy.AddComponent(space)
guy.AddComponent(collision)
w.AddEntity(guy)
}
示例5: NewRock
func NewRock(position engi.Point) *engi.Entity {
rock := engi.NewEntity([]string{"RenderSystem", "FallingSystem", "CollisionSystem", "SpeedSystem"})
texture := engi.Files.Image("rock.png")
render := engi.NewRenderComponent(texture, engi.Point{4, 4}, "rock")
space := &engi.SpaceComponent{position, texture.Width() * render.Scale.X, texture.Height() * render.Scale.Y}
collision := &engi.CollisionComponent{Solid: true}
rock.AddComponent(render)
rock.AddComponent(space)
rock.AddComponent(collision)
return rock
}
示例6: CreateEntity
func (game *GameWorld) CreateEntity(point *engi.Point, spriteSheet *engi.Spritesheet, action *engi.AnimationAction) *ecs.Entity {
entity := ecs.NewEntity([]string{"AnimationSystem", "RenderSystem", "ControlSystem"})
space := &engi.SpaceComponent{*point, 150, 150}
render := engi.NewRenderComponent(spriteSheet.Cell(action.Frames[0]), engi.Point{3, 3}, "hero")
animation := engi.NewAnimationComponent(spriteSheet.Drawables(), 0.1)
animation.AddAnimationActions(actions)
animation.SelectAnimationByAction(action)
entity.AddComponent(render)
entity.AddComponent(space)
entity.AddComponent(animation)
return entity
}
示例7: generateBackground
// generateBackground creates a background of green tiles - might not be the most efficient way to do this
func generateBackground() *engi.RenderComponent {
rect := image.Rect(0, 0, int(boxWidth), int(boxHeight))
img := image.NewNRGBA(rect)
c1 := color.RGBA{102, 153, 0, 255}
for i := rect.Min.X; i < rect.Max.X; i++ {
for j := rect.Min.Y; j < rect.Max.Y; j++ {
img.Set(i, j, c1)
}
}
bgTexture := engi.NewImageObject(img)
fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "Background1")
fieldRender.SetPriority(engi.Background)
return fieldRender
}
示例8: generateHUDBackground
// generateHUDBackground creates a violet HUD on the left side of the screen - might be inefficient
func generateHUDBackground(width, height float32) *ecs.Entity {
rect := image.Rect(0, 0, int(width), int(height))
img := image.NewNRGBA(rect)
c1 := color.RGBA{255, 0, 255, 180}
for i := rect.Min.X; i < rect.Max.X; i++ {
for j := rect.Min.Y; j < rect.Max.Y; j++ {
img.Set(i, j, c1)
}
}
bgTexture := engi.NewImageObject(img)
field := ecs.NewEntity([]string{"RenderSystem"})
fieldRender := engi.NewRenderComponent(engi.NewTexture(bgTexture), engi.Point{1, 1}, "HUDBackground1")
fieldRender.SetPriority(hudBackgroundPriority)
fieldSpace := &engi.SpaceComponent{engi.Point{-1, -1}, width, height}
field.AddComponent(fieldRender)
field.AddComponent(fieldSpace)
return field
}
示例9: Setup
func (game *GameWorld) Setup() {
engi.SetBg(0x2d3739)
game.AddSystem(&engi.RenderSystem{})
gameMap := ecs.NewEntity([]string{"RenderSystem"})
tilemap := engi.NewTilemap(
[][]string{
{"0", "2", "0"},
{"4", "5", "1"},
{"2", "3", "4"},
{"5", "1", "2"}},
engi.Files.Image("sheet"), 16)
mapRender := engi.NewRenderComponent(tilemap, engi.Point{1, 1}, "map")
mapSpace := &engi.SpaceComponent{engi.Point{100, 100}, 0, 0}
gameMap.AddComponent(mapRender)
gameMap.AddComponent(mapSpace)
game.AddEntity(gameMap)
}
示例10: Setup
func (game *GameWorld) Setup(w *ecs.World) {
engi.SetBg(0x2d3739)
w.AddSystem(&engi.RenderSystem{})
w.AddSystem(&HideSystem{})
guy := ecs.NewEntity([]string{"RenderSystem", "HideSystem"})
texture := engi.Files.Image("rock.png")
render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")
collision := &engi.CollisionComponent{Solid: true, Main: true}
width := texture.Width() * render.Scale().X
height := texture.Height() * render.Scale().Y
space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}
guy.AddComponent(render)
guy.AddComponent(space)
guy.AddComponent(collision)
w.AddEntity(guy)
}
示例11: GenerateSquareComonent
// GenerateSquareComonent creates a square, alternating two colors, with given size and priority levl
func GenerateSquareComonent(c1, c2 color.NRGBA, w, h float32, priority engi.PriorityLevel) *engi.RenderComponent {
rect := image.Rect(0, 0, int(w), int(h))
img := image.NewNRGBA(rect)
if c1 == c2 {
// Solid color
for i := 0; i < len(img.Pix); i += 4 {
img.Pix[i] = c1.R
img.Pix[i+1] = c1.G
img.Pix[i+2] = c1.B
img.Pix[i+3] = c1.A
}
} else {
// TODO: we can optimize this as well
for i := rect.Min.X; i < rect.Max.X; i++ {
for j := rect.Min.Y; j < rect.Max.Y; j++ {
if i%40 > 20 {
if j%40 > 20 {
img.Set(i, j, c1)
} else {
img.Set(i, j, c2)
}
} else {
if j%40 > 20 {
img.Set(i, j, c2)
} else {
img.Set(i, j, c1)
}
}
}
}
}
bgTexture := engi.NewImageObject(img)
fieldRender := engi.NewRenderComponent(engi.NewRegion(engi.NewTexture(bgTexture), 0, 0, int(w), int(h)), engi.Point{1, 1}, "")
fieldRender.SetPriority(priority)
return fieldRender
}
示例12: Setup
func (game *GameWorld) Setup(w *ecs.World) {
engi.SetBg(0x2d3739)
w.AddSystem(&engi.RenderSystem{})
// Create an entity part of the Render and Scale systems
guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
// Retrieve a texture
texture := engi.Files.Image("icon.png")
// Create RenderComponent... Set scale to 8x, give lable "guy"
render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")
width := texture.Width() * render.Scale().X
height := texture.Height() * render.Scale().Y
space := &engi.SpaceComponent{engi.Point{0, 0}, width, height}
guy.AddComponent(render)
guy.AddComponent(space)
w.AddEntity(guy)
}
示例13: Setup
func (game *RockScene) Setup(w *ecs.World) {
engi.SetBg(0x2d3739)
w.AddSystem(&engi.RenderSystem{})
w.AddSystem(&ScaleSystem{})
w.AddSystem(&SceneSwitcherSystem{NextScene: "IconScene", WaitTime: time.Second * 3})
guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
texture := engi.Files.Image("rock.png")
render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "rock")
collision := &engi.CollisionComponent{Solid: true, Main: true}
width := texture.Width() * render.Scale().X
height := texture.Height() * render.Scale().Y
space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}
guy.AddComponent(render)
guy.AddComponent(space)
guy.AddComponent(collision)
w.AddEntity(guy)
}