首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的程序出错!此操作没有呈现队列。

我的程序出错!此操作没有呈现队列。
EN

Stack Overflow用户
提问于 2019-10-15 00:26:58
回答 1查看 1.1K关注 0票数 1

我正在用红宝石和丝瓜制作一个游戏,我得到了一个错误:

C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/gosu-0.14.5-x64-mingw32/lib/gosu/patches.rb:72:in C:/Ruby26-x64/

!/bullet.rb:14:indraw_rot': There is no rendering queue for this operation (RuntimeError) from C:/Ruby26-x64/destroy!/bullet.rb:14:in从C:/Ruby26-x64/!/player.rb:45:infire' from C:/Ruby26-x64/destroy!/destroy.rb:36:inupdate从C:/Ruby26-x64/!/destroy.rb:40:in‘在0.517s中完成

我已经尝试将draw_rot类中的avail类更改为,但没有任何效果。

我的类

破坏

代码语言:javascript
复制
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

子弹

代码语言:javascript
复制
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

播放器

代码语言:javascript
复制
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

敌人

代码语言:javascript
复制
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

我一点也不明白。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-15 02:18:07

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

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

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58385630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档