mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
examples/sprites: Apply ColorM change only once
This commit is contained in:
parent
3b3179e33e
commit
e84b717c95
@ -33,8 +33,6 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ebitenImage *ebiten.Image
|
ebitenImage *ebiten.Image
|
||||||
ebitenImageWidth = 0
|
|
||||||
ebitenImageHeight = 0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sprite struct {
|
type Sprite struct {
|
||||||
@ -81,14 +79,10 @@ const (
|
|||||||
MaxSprites = 50000
|
MaxSprites = 50000
|
||||||
)
|
)
|
||||||
|
|
||||||
var sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
|
var (
|
||||||
|
sprites = &Sprites{make([]*Sprite, MaxSprites), 500}
|
||||||
var op *ebiten.DrawImageOptions
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
op = &ebiten.DrawImageOptions{}
|
op = &ebiten.DrawImageOptions{}
|
||||||
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
|
||||||
@ -125,11 +119,15 @@ Press <- or -> to change the number of sprites`, ebiten.CurrentFPS(), sprites.nu
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
img, _, err := ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ebitenImageWidth, ebitenImageHeight = ebitenImage.Size()
|
w, h := img.Size()
|
||||||
|
ebitenImage, _ = ebiten.NewImage(w, h, ebiten.FilterNearest)
|
||||||
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
op.ColorM.Scale(1, 1, 1, 0.5)
|
||||||
|
ebitenImage.DrawImage(img, op)
|
||||||
for i := range sprites.sprites {
|
for i := range sprites.sprites {
|
||||||
w, h := ebitenImage.Size()
|
w, h := ebitenImage.Size()
|
||||||
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h)
|
||||||
|
Loading…
Reference in New Issue
Block a user