File tree 3 files changed +12
-9
lines changed
3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ func (c *Camera) SetLightRGB(min, max color.NRGBA) {
223
223
// Update - updates the camera view
224
224
func (c * Camera ) Update (sprites []Sprite ) {
225
225
// clear horizontal buffer by making a new one
226
- c .floorLvl .clear (c .w , c .h )
226
+ c .floorLvl .initialize (c .w , c .h )
227
227
228
228
// reset convergence point
229
229
c .convergenceDistance = - 1
@@ -761,7 +761,7 @@ func (c *Camera) createLevels(numLevels int) []*level {
761
761
// creates floor slices for raycasting floor
762
762
func (c * Camera ) createFloorLevel () * horLevel {
763
763
horizontalLevel := new (horLevel )
764
- horizontalLevel .clear (c .w , c .h )
764
+ horizontalLevel .initialize (c .w , c .h )
765
765
return horizontalLevel
766
766
}
767
767
Original file line number Diff line number Diff line change @@ -38,8 +38,13 @@ func sliceView(width, height int) []*image.Rectangle {
38
38
type horLevel struct {
39
39
// horBuffer is the image representing the pixels to render during the update
40
40
horBuffer * image.RGBA
41
+ // image is the ebitengine image object rendering the horBuffer during draw
42
+ image * ebiten.Image
41
43
}
42
44
43
- func (h * horLevel ) clear (width , height int ) {
45
+ func (h * horLevel ) initialize (width , height int ) {
44
46
h .horBuffer = image .NewRGBA (image .Rect (0 , 0 , width , height ))
47
+ if h .image == nil {
48
+ h .image = ebiten .NewImage (width , height )
49
+ }
45
50
}
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package raycaster
3
3
import (
4
4
"image"
5
5
"image/color"
6
- "log"
7
6
8
7
"github.com/hajimehoshi/ebiten/v2"
9
8
)
@@ -31,13 +30,12 @@ func (c *Camera) Draw(screen *ebiten.Image) {
31
30
}
32
31
33
32
// draw textured floor
34
- floorImg := ebiten .NewImageFromImage (c .floorLvl .horBuffer )
35
- if floorImg == nil {
36
- log .Fatal ("floorImg is nil" )
37
- } else {
33
+ if c .floorLvl != nil && c .floorLvl .image != nil {
34
+ c .floorLvl .image .WritePixels (c .floorLvl .horBuffer .Pix )
35
+
38
36
op := & ebiten.DrawImageOptions {}
39
37
op .Filter = ebiten .FilterNearest
40
- screen .DrawImage (floorImg , op )
38
+ screen .DrawImage (c . floorLvl . image , op )
41
39
}
42
40
43
41
// draw sprites
You can’t perform that action at this time.
0 commit comments