Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Ruby/Sdl, beginner problem, making sprites...
Konrad Slabig
2/17/2009 5:46:00 PM
Hi. I'm beginner in programming, and also in ruby.
I have installed Ruby/Sdl
(
http://www.kmc.gr.jp/~ohai/rubysdl_ref_2.en.html...
) 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?
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Ruby/Sdl, beginner problem, making sprites...
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password