我的程序出错了!!!!此操作没有渲染队列

Error in my program!!!! There is no rendering queue for this operation

我正在使用 ruby 和 gosu 创建游戏,但出现错误:

C:/Ruby26-x64/destroy!/bullet.rb:14:in draw_rot': There is no rendering queue for this operation (RuntimeError) from C:/Ruby26-x64/destroy!/bullet.rb:14:indraw' from C:/Ruby26-x64/destroy!/player.rb:45:in fire' from C:/Ruby26-x64/destroy!/destroy.rb:36:inupdate' from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/gosu-0.14.5-x64-mingw32/lib/gosu/patches.rb:72:in tick' from C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/gosu-0.14.5-x64-mingw32/lib/gosu/patches.rb:72:intick' from C:/Ruby26-x64/destroy!/destroy.rb:40:in `' [Finished in 0.517s]

我试过把子弹中的绘图class改成draw_rot,但是没用。

我的类

毁灭

require 'gosu'
require 'cmath'
require_relative 'player.rb'
require_relative 'enemy.rb'
require_relative 'bullet.rb'
class Destroy < Gosu::Window
  def initialize
    super(800, 600)
    self.caption = 'Destroy!'
    @player = Player.new(self)
    @enemies = []
    @enemies.push(Enemy.new(self))
  end

  def draw
    @player.draw
    @enemies.each do |enemy|
      enemy.draw
    end
  end

  def update
    @player.righturn if button_down?(Gosu::KbRight)
    @player.lefturn if button_down?(Gosu::KbLeft)
    @player.startmove
    @player.move if button_down?(Gosu::KbUp)
    @freq = 0.0025
    if rand < @freq
      @enemies.push(Enemy.new(self))
    end
    @enemies.each do |enemy|
      enemy.move
      enemy.update(@player.x, @player.y)
    end
    if @freq < 0.5
      @freq += 0.0002
    end
    @player.fire(self)
  end
end
window = Destroy.new
window.show

子弹

class Bullet
  attr_accessor :x
  attr_accessor :y
  attr_accessor :fired

  def initialize(window)
    @image = Gosu::Image.new('C:\Ruby26-x64\destroy!\images\bullet.png')
    @fired = 0
    @x = 0
    @y = 0
  end

  def draw(x, y)
    @x = x
    @y = y
    @image.draw_rot(x, y, 1, 0)
    @fired = 1
  end

  def update(angle)
    @xspeed = Gosu.offset_x(angle, 2)
    @yspeed = Gosu.offset_y(angle, 2)
    if (@x > 800 || @x < 0 || @y > 600 || @y < 0)
      @fired = 0
    end
  end
end

玩家

require_relative 'bullet.rb'
require 'gosu'
class Player
  attr_accessor :x
  attr_accessor :y

  def initialize(window)
    @x = 200
    @y = 200
    @xspeed = 0
    @yspeed = 0
    @angle = 0
    @image = Gosu::Image.new('C:/Ruby26-x64/destroy!/images/man.png')
  end

  def draw
    @image.draw_rot(@x, @y, 1, @angle)
  end

  def righturn
    @angle += 3
  end

  def lefturn
    @angle -= 3
  end

  def startmove
    @xspeed = Gosu.offset_x(@angle, 2)
    @yspeed = Gosu.offset_y(@angle, 2)
  end

  def move
    if @x > 767
      @xpeed = 0
      @x = 767
    end
    if @x < 33
      @xpeed = 0
      @x = 33
    end
    if @y > 567
      @yspeed = 0
      @y = 567
    end
    @x += @xspeed
    @y += @yspeed
  end

  def fire(window)
    @bullet = Bullet.new(window)
    @bullet.draw(@x, @y)
    while @bullet.fired = 1
      @bullet.update(@angle)
    end
  end
end

敌人

require 'cmath'
class Enemy
  def initialize(window)
    @flipped = 0
    @x = rand(800 - 2 * 30) + 30
    @y = rand(600 - 2 * 30) + 30
    @firefreq = 1 / 60
    @health = 5
    @numkilled = 0
    @dead = 0
    @xspeed = 0
    @yspeed = 0
    @angle = 0
    @image = Gosu::Image.new('C:/Ruby26-x64/destroy!/images/enemy.png')
    @imageflipped = Gosu::Image.new('C:/Ruby26-x64/destroy!/images/enemyflip.png')
  end

  def gethit
    @health -= 1
  end

  def die
    @numkilled += 1
    @dead = 1
  end

  def move
    if rand < 0.1
      @xspeed = rand(-3..3)
      @yspeed = rand(-3..3)
    end
    if @x + @xspeed > 800
      @x = 800
    end
    if @x + @xspeed < 0
      @x = 0
    end
    if @y + @yspeed > 600
      @y = 600
    end
    if @y + @yspeed < 0
      @y = 0
    end
    if !(@y + @yspeed < 0 && @y + @yspeed > 600 && @x + @xspeed < 0 && @x + @xspeed > 800)
      @y += @yspeed
      @x += @xspeed
    end
  end

  def draw
    if @dead == 0
      if @flipped == 1
        @imageflipped.draw_rot(@x, @y, 1, @angle)
      end
      if @flipped == 0
        @image.draw_rot(@x, @y, 1, @angle)
      end
    end
  end

  def update(xdist, ydist)
    if @x < xdist
      (@angle = CMath.atan((ydist - @y) / (xdist - @x)) * 180 / 3.14159265358979323846264338327950289)
      @flipped = 0
    end
    if @x > xdist
      (@angle = CMath.atan(-(ydist - @y) / (@x - xdist)) * 180 / 3.14159265358979323846264338327950289)
      @flipped = 1
    end
  end
end

我完全不明白。

您的 Destroy#update 方法调用 Player#fire,后者调用 Bullet#draw,后者调用 Gosu::Image#draw_rot。您不能从主 update 方法中调用 draw 方法。

您必须将 @bullet.draw 方法调用从 Player#fire(在主 update 期间调用)移出并移至 Player#draw(在主 update 期间调用) draw)