mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/masking: Rename variables
This commit is contained in:
parent
9730af7976
commit
023315c256
@ -35,7 +35,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
bgImage *ebiten.Image
|
bgImage *ebiten.Image
|
||||||
fgImage *ebiten.Image
|
fgImage *ebiten.Image
|
||||||
maskImage *ebiten.Image
|
maskedFgImage *ebiten.Image
|
||||||
spotLightImage *ebiten.Image
|
spotLightImage *ebiten.Image
|
||||||
spotLightX = 0
|
spotLightX = 0
|
||||||
spotLightY = 0
|
spotLightY = 0
|
||||||
@ -55,7 +55,7 @@ func init() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
maskImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
maskedFgImage, _ = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
|
||||||
|
|
||||||
// Initialize the spot light image.
|
// Initialize the spot light image.
|
||||||
const r = 64
|
const r = 64
|
||||||
@ -100,30 +100,30 @@ func update(screen *ebiten.Image) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
maskImage.Clear()
|
maskedFgImage.Clear()
|
||||||
|
|
||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(float64(spotLightX), float64(spotLightY))
|
op.GeoM.Translate(float64(spotLightX), float64(spotLightY))
|
||||||
maskImage.DrawImage(spotLightImage, op)
|
maskedFgImage.DrawImage(spotLightImage, op)
|
||||||
|
|
||||||
// Use 'source-out' composite mode so that the source image (fgImage) is used but the alpha
|
// Use 'source-out' composite mode so that the source image (fgImage) is used but the alpha
|
||||||
// is determined by the destination image (maskImage). With source-out, the destination image
|
// is determined by the destination image (maskedFgImage). With source-out, the destination
|
||||||
// values are not used at the result image.
|
// image values are not used at the result image.
|
||||||
//
|
//
|
||||||
// If the alpha value of the destination is 0xff, the source at the point is not adopted.
|
// If the alpha value of the destination is 0xff, the source at the point is not adopted.
|
||||||
// In the opposite way, if the alpha value of the destination is 0, the source at the point
|
// In the opposite way, if the alpha value of the destination is 0, the source at the point
|
||||||
// is fully adopted. As alpha values outside of the spot light image are 0, the source values
|
// is fully adopted. As alpha values outside of the spot light image are 0, the source
|
||||||
// are fully adopted there. As a result, the maskImage draws the source image with a hole
|
// values are fully adopted there. As a result, the maskedFgImage draws the source image
|
||||||
// that shape is spotLightImage.
|
// with a hole that shape is spotLightImage.
|
||||||
//
|
//
|
||||||
// See also https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcout.
|
// See also https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators_srcout.
|
||||||
op = &ebiten.DrawImageOptions{}
|
op = &ebiten.DrawImageOptions{}
|
||||||
op.CompositeMode = ebiten.CompositeModeSourceOut
|
op.CompositeMode = ebiten.CompositeModeSourceOut
|
||||||
maskImage.DrawImage(fgImage, op)
|
maskedFgImage.DrawImage(fgImage, op)
|
||||||
|
|
||||||
screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff})
|
screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff})
|
||||||
screen.DrawImage(bgImage, &ebiten.DrawImageOptions{})
|
screen.DrawImage(bgImage, &ebiten.DrawImageOptions{})
|
||||||
screen.DrawImage(maskImage, &ebiten.DrawImageOptions{})
|
screen.DrawImage(maskedFgImage, &ebiten.DrawImageOptions{})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user