Forums Archived

The forums are being archived. See this topic for more information.

Help with blit.

Get help and support with Rubygame

Help with blit.

Postby HOMER-16 » Fri Aug 27, 2010 6:02 pm

main.rb
Code: Select all
require 'rubygame'
require 'map.rb'
include Rubygame

resources=File.dirname(__FILE__)+"/Data"

Rubygame.init

$screen=Screen.new [1000,1000]
events=EventQueue.new
clock=Clock.new

$grid=Surface.load("Data/overmap.bmp")
$grid.blit($screen,[0,0],[0,0,1000,1000])
while 1


end


Map.rb
Code: Select all
require 'rubygame'
require 'yaml'
include Rubygame
test_map = File.open("Data/test.yaml"){ |mapfile| YAML.load(mapfile) }
test_map["tiles"].each_with_index { |rows, r|
   rows.each_with_index { |tile, c|
      case tile
      when 0
      image = Surface.load('Data/grass1.bmp')
    image.set_colorkey( image.get_at([0,0]) )
      h=50
    w=50
    when 1
      image = Surface.load('Data/mount.bmp')
      image.set_colorkey( image.get_at([0,0]) )
      h=50
    w=50
    when 2
    image = Surface.load('Data/ground1.bmp')
      h=25
    w=50
    when 3
      image = Surface.load('Data/forest1.bmp')
    image.set_colorkey( image.get_at([0,0]) )
    h=50
    w=50
    when 4
      image = Surface.load('Data/water1.bmp')
    h=25
    w=50
    when 5
      image = Surface.load('Data/bridge.bmp')
  h=25
  w=50
  end
  x=c*15
  y=r*6
#the problem is here 
image.blit($grid,[x,y],[0,0,w,h])
   $screen.update
  }
  }


it was saying wrong argument type nil (expecting data) but now it's running but not bliting anything to the screen save a grid in overmap.png
HOMER-16
 
Posts: 13
Joined: Sat Dec 19, 2009 6:02 am

Re: Help with blit.

Postby indspenceable » Fri Aug 27, 2010 9:45 pm

It looks you are trying to display the screen (which happens in map.rb) before you setup the grid variable - thus, the value of $grid is evaluating to nil. You rpobably want to A) Make test_map into a global variable ($test_map?) and then b) wrap the part of the file where you display the map in a method. Then, in the while loop at the end of your program, you can just call "display_map".
indspenceable
 
Posts: 8
Joined: Fri Jun 18, 2010 7:47 am


Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron