0

I am trying to implement the effect of hovering over and selecting several images. The hovering effect works fine, the problem lies with selecting the images. After selecting back and forth between the images a few times, the program will exit and gives me the error and I'm not sure what causes the problem:

/Library/Ruby/Gems/2.6.0/gems/gosu-1.4.5/lib/gosu/compat.rb:153:in `draw_rect': Expected argument 0 of type double, but got NilClass nil (TypeError) in SWIG method 'Gosu::draw_rect'.

main draw function


    def draw
        draw_hover(area_clicked(mouse_x,mouse_y))
        draw_background()

        i=0
        while i < @album_count
            location = @albums[i].album_cover
            draw_albums(location,i,i)
            i+=1
        end

        if @selected
            draw_rect(@x,@y,150,150,Gosu::Color.argb(0x800055ff),z=ZOrder::HOVER)
        end
    end

draws rectangle over image to create hovering effect

def draw_hover(album_hovered)
        if album_hovered != 0
            case album_hovered
            when 1
                x=25
                y=25
            when 2
                x=200
                y=25
            when 3
                x=25
                y=200
            when 4
                x=200
                y=200
            end
            draw_rect(x,y,150,150,Gosu::Color.argb(0x800055ff),z=ZOrder::HOVER)
        end
    end

def button_down(id)
        case id
        when Gosu::MsLeft
            @selected = false
            if area_clicked(mouse_x,mouse_y) == 1
                @selected = true
                @x =25
                @y =25
            elsif area_clicked(mouse_x,mouse_y) == 2
                @selected = true
                @x =200
                @y =25
            elsif area_clicked(mouse_x,mouse_y) == 3
                @selected = true
                @x =25
                @y =200
            elsif area_clicked(mouse_x,mouse_y) == 4
                @selected = true
                @x =200
                @y =200
            elsif area_clicked(mouse_x,mouse_y) == 0
                @selected = false
            end
        end
    end
kriloots
  • 69
  • 9

0 Answers0