Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Sector Five from Learning Game Programming w/Ruby
- - By mxld Date 2016-10-30 20:44
Hi,

I'm working through Learning Game Programming with Ruby. I'm on Chapter 4, Creating a Sprite based game. When I run ruby sector_five.rb. The window opens but the space ship doesn't show. Here is my code for sector_five.rb:
require 'gosu'
require_relative 'player'

class SectorFive < Gosu::Window
  def initialize
    super(800, 600)
    self.caption = 'Sector Five'
    @player = Player.new(self)
  end
end

def draw
  @player.draw
end

window = SectorFive.new
window.show


Here is my code for player.rb:
class Player
  def initialize(window)
    @x = 200
    @y = 200
    @angle = 0
    @image = Gosu::Image.new('images/ship.png')
  end

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


Here are how my files are organized


I've been looking at it for the past day and trying different paths for ship.png, none work. I don't get an error the game window pops open but there is no ship. I read something in StackOverflow about paths and files. Mine seems ok. What do I need to fix? What am I missing?

Thanks.
Parent - - By jlnr (dev) Date 2016-10-30 22:08
def draw needs to be inside the body of class SectorFive to override the empty method "draw" in the Gosu::Window base class:

class SectorFive < Gosu::Window

  ..
  def draw
    ..
  end
end


You have defined a global method called draw, which is never called by anybody.
Parent - By mxld Date 2016-10-30 22:49
Thank you so much. I looked at it for hours. I should have made sure all the closing ends were where they belong. Thank you so much!
Up Topic Gosu / Gosu Exchange / Sector Five from Learning Game Programming w/Ruby

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill