Hi. I’m beginner in programming, and also in ruby.
I have installed Ruby/Sdl
(Ruby/SDL Reference Manual) and I have
a problem.
I tried to make a screen and surface, and it didn’t worked. I’m looking
for answer for Two days, so now I’m asking here…
My code:
#--------------
#--------------
#--------------
require ‘sdl’
class Sprite
attr_accessor :x
attr_accessor :y
attr_accessor :alpha
attr_accessor :image
def initialize(path,x=0,y=0,alpha=256)
# Jeden X odpowiada 1/640 szerokosci ekranu, jakikolwiek szeroki by
nie był.
@x = ($screen.w/640)*x
# Jeden Y odpowiada 1/480 szerokosci ekranu, jakikolwiek wysoki by
nie był.
@y = ($screen.h/480)*y
@alpha = alpha
@image = SDL::Surface.load_bmp(path.to_s)
@image.set_alpha(SDL::SRCALPHA,@alpha)
@image.set_color_key( SDL::SRCCOLORKEY ,0)
@image = @image.display_format
$sprites << self
update
end
def update
$screen.put(@image,@x,@y)
end
end
SDL.init( SDL::INIT_VIDEO )
$screen = SDL::Screen.open(640,480,16,SDL::SWSURFACE)
$sprites = []
$char = Sprite.new(“tilek.bmp”,320,240)
loop do
while event = SDL::Event.poll
case event
when SDL::Event::Quit
exit
when SDL::Event::KeyDown
$char.x += 32
$char.y += 2
end
end
background_color = $screen.format.map_rgb(0,0,0)
$screen.fillRect(0,0,640,480,background_color)
for sprite in $sprites
sprite.update
end
inny update, do obslugi 2-warstwowych ramów (???) czy czegoś takiego
$screen.flip
update całego okna
$screen.update_rect(0,0,$screen.w,$screen.h)
end
EnD…
--------------
--------------
Ok… When I’m looking at the samples in Ruby/Sdl files, there are
modules and everything that looks very very similar to that what I did
above. But Mine is not working ^^".
Can anyone help?