mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +01:00
Change TexturePart
This commit is contained in:
parent
87d49546f3
commit
9c18aef725
@ -48,9 +48,8 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
|
|||||||
srcX := (code % xCharNum) * assets.TextImageCharWidth
|
srcX := (code % xCharNum) * assets.TextImageCharWidth
|
||||||
srcY := (code / xCharNum) * assets.TextImageCharHeight
|
srcY := (code / xCharNum) * assets.TextImageCharHeight
|
||||||
parts = append(parts, ebiten.TexturePart{
|
parts = append(parts, ebiten.TexturePart{
|
||||||
LocationX: locationX,
|
Dst: ebiten.Rect{locationX, locationY, assets.TextImageCharWidth, assets.TextImageCharHeight},
|
||||||
LocationY: locationY,
|
Src: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight},
|
||||||
Source: ebiten.Rect{srcX, srcY, assets.TextImageCharWidth, assets.TextImageCharHeight},
|
|
||||||
})
|
})
|
||||||
locationX += assets.TextImageCharWidth
|
locationX += assets.TextImageCharWidth
|
||||||
}
|
}
|
||||||
|
@ -48,9 +48,8 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
|
|||||||
x := (code % 16) * charWidth
|
x := (code % 16) * charWidth
|
||||||
y := ((code - 32) / 16) * charHeight
|
y := ((code - 32) / 16) * charHeight
|
||||||
parts = append(parts, ebiten.TexturePart{
|
parts = append(parts, ebiten.TexturePart{
|
||||||
LocationX: locationX,
|
Dst: ebiten.Rect{locationX, locationY, charWidth, charHeight},
|
||||||
LocationY: locationY,
|
Src: ebiten.Rect{x, y, charWidth, charHeight},
|
||||||
Source: ebiten.Rect{x, y, charWidth, charHeight},
|
|
||||||
})
|
})
|
||||||
locationX += charWidth
|
locationX += charWidth
|
||||||
}
|
}
|
||||||
|
@ -147,15 +147,9 @@ func drawBlocks(context ebiten.GraphicsContext, textures *Textures, blocks [][]B
|
|||||||
}
|
}
|
||||||
locationX := i * blockWidth
|
locationX := i * blockWidth
|
||||||
locationY := j * blockHeight
|
locationY := j * blockHeight
|
||||||
source := ebiten.Rect{
|
dst := ebiten.Rect{locationX, locationY, blockWidth, blockHeight}
|
||||||
(int(block) - 1) * blockWidth, 0,
|
src := ebiten.Rect{(int(block) - 1) * blockWidth, 0, blockWidth, blockHeight}
|
||||||
blockWidth, blockHeight}
|
parts = append(parts, ebiten.TexturePart{dst, src})
|
||||||
parts = append(parts,
|
|
||||||
ebiten.TexturePart{
|
|
||||||
LocationX: locationX,
|
|
||||||
LocationY: locationY,
|
|
||||||
Source: source,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocksTexture := textures.GetTexture("blocks")
|
blocksTexture := textures.GetTexture("blocks")
|
||||||
|
@ -59,9 +59,8 @@ func drawTitleBackground(context ebiten.GraphicsContext, textures *Textures, c i
|
|||||||
for j := -1; j < ScreenHeight/textureHeight+1; j++ {
|
for j := -1; j < ScreenHeight/textureHeight+1; j++ {
|
||||||
for i := 0; i < ScreenWidth/textureWidth+1; i++ {
|
for i := 0; i < ScreenWidth/textureWidth+1; i++ {
|
||||||
parts = append(parts, ebiten.TexturePart{
|
parts = append(parts, ebiten.TexturePart{
|
||||||
LocationX: i * textureWidth,
|
Dst: ebiten.Rect{i * textureWidth, j * textureHeight, textureWidth, textureHeight},
|
||||||
LocationY: j * textureHeight,
|
Src: ebiten.Rect{0, 0, textureWidth, textureHeight},
|
||||||
Source: ebiten.Rect{0, 0, textureWidth, textureHeight},
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error {
|
|||||||
geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY))
|
geo.Concat(ebiten.ScaleGeometry(scaleX, scaleY))
|
||||||
geo.Concat(ebiten.RotateGeometry(float64(g.count%720) * 2 * math.Pi / 720))
|
geo.Concat(ebiten.RotateGeometry(float64(g.count%720) * 2 * math.Pi / 720))
|
||||||
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
|
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
|
||||||
clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
|
//clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
|
||||||
|
clr := ebiten.ColorMatrixI()
|
||||||
ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr)
|
ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
25
graphics.go
25
graphics.go
@ -31,9 +31,8 @@ type Rect struct {
|
|||||||
|
|
||||||
// A TexturePart represents a part of a texture.
|
// A TexturePart represents a part of a texture.
|
||||||
type TexturePart struct {
|
type TexturePart struct {
|
||||||
LocationX int
|
Dst Rect
|
||||||
LocationY int
|
Src Rect
|
||||||
Source Rect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Drawer is the interface that draws itself.
|
// A Drawer is the interface that draws itself.
|
||||||
@ -45,7 +44,7 @@ type Drawer interface {
|
|||||||
func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
||||||
w, h := texture.Size()
|
w, h := texture.Size()
|
||||||
parts := []TexturePart{
|
parts := []TexturePart{
|
||||||
{0, 0, Rect{0, 0, w, h}},
|
{Rect{0, 0, w, h}, Rect{0, 0, w, h}},
|
||||||
}
|
}
|
||||||
return g.Texture(texture).Draw(parts, geo, color)
|
return g.Texture(texture).Draw(parts, geo, color)
|
||||||
}
|
}
|
||||||
@ -54,7 +53,7 @@ func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, c
|
|||||||
func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error {
|
func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error {
|
||||||
w, h := renderTarget.Size()
|
w, h := renderTarget.Size()
|
||||||
parts := []TexturePart{
|
parts := []TexturePart{
|
||||||
{0, 0, Rect{0, 0, w, h}},
|
{Rect{0, 0, w, h}, Rect{0, 0, w, h}},
|
||||||
}
|
}
|
||||||
return g.RenderTarget(renderTarget).Draw(parts, geo, color)
|
return g.RenderTarget(renderTarget).Draw(parts, geo, color)
|
||||||
}
|
}
|
||||||
@ -114,14 +113,14 @@ func v(y int, height int) float32 {
|
|||||||
func textureQuads(parts []TexturePart, width, height int) []shader.TextureQuad {
|
func textureQuads(parts []TexturePart, width, height int) []shader.TextureQuad {
|
||||||
quads := make([]shader.TextureQuad, 0, len(parts))
|
quads := make([]shader.TextureQuad, 0, len(parts))
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
x1 := float32(part.LocationX)
|
x1 := float32(part.Dst.X)
|
||||||
x2 := float32(part.LocationX + part.Source.Width)
|
x2 := float32(part.Dst.X + part.Dst.Width)
|
||||||
y1 := float32(part.LocationY)
|
y1 := float32(part.Dst.Y)
|
||||||
y2 := float32(part.LocationY + part.Source.Height)
|
y2 := float32(part.Dst.Y + part.Dst.Height)
|
||||||
u1 := u(part.Source.X, width)
|
u1 := u(part.Src.X, width)
|
||||||
u2 := u(part.Source.X+part.Source.Width, width)
|
u2 := u(part.Src.X+part.Src.Width, width)
|
||||||
v1 := v(part.Source.Y, height)
|
v1 := v(part.Src.Y, height)
|
||||||
v2 := v(part.Source.Y+part.Source.Height, height)
|
v2 := v(part.Src.Y+part.Src.Height, height)
|
||||||
quad := shader.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2}
|
quad := shader.TextureQuad{x1, x2, y1, y2, u1, u2, v1, v2}
|
||||||
quads = append(quads, quad)
|
quads = append(quads, quad)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user