Class: Xibe::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/xibe.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, fullscreen = false, fps = 30) ⇒ Application

width, height: window size; fullscreen: fullscreen mode; fps: frames per seconds



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/xibe.rb', line 245

def initialize(width, height, fullscreen = false, fps=30)
  @width = width
  @height = height
  @fullscreen = fullscreen
  @fps = fps
  @@window = self
  
  SDL.init(SDL::INIT_EVERYTHING)

  if SDL::Joystick.num > 0
    $joystick = SDL::Joystick.open(0)
  end

  #SDL::Mixer.open(22050)
  SDL::Mouse.hide
  mode = @fullscreen == true ? SDL::FULLSCREEN|SDL::HWSURFACE : SDL::HWSURFACE
  @screen = SDL::setVideoMode @width, @height, 16, mode
end

Instance Attribute Details

#fpsObject

Returns the value of attribute fps.



243
244
245
# File 'lib/xibe.rb', line 243

def fps
  @fps
end

#heightObject

Returns the value of attribute height.



243
244
245
# File 'lib/xibe.rb', line 243

def height
  @height
end

#sceneObject

Returns the value of attribute scene.



243
244
245
# File 'lib/xibe.rb', line 243

def scene
  @scene
end

#widthObject

Returns the value of attribute width.



243
244
245
# File 'lib/xibe.rb', line 243

def width
  @width
end

#xObject

Returns the value of attribute x.



243
244
245
# File 'lib/xibe.rb', line 243

def x
  @x
end

#yObject

Returns the value of attribute y.



243
244
245
# File 'lib/xibe.rb', line 243

def y
  @y
end

Instance Method Details

#display(scene) ⇒ Object

Sets the scene to display



314
315
316
317
# File 'lib/xibe.rb', line 314

def display(scene)
  @scene = scene
  @screen.set_clip_rect(0,0,@scene.width,@scene.height)
end

#drawObject



309
310
311
# File 'lib/xibe.rb', line 309

def draw
  scene_draw unless @scene.nil?
end

#icon=(filename) ⇒ Object

Sets the window icon



270
271
272
# File 'lib/xibe.rb', line 270

def icon=(filename)
  SDL::WM.icon = SDL::Surface.load filename
end

#inputObject



301
302
303
# File 'lib/xibe.rb', line 301

def input
  scene_input unless @scene.nil?
end

#runObject

Run application



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/xibe.rb', line 275

def run
  timer = Timer.new
  loop do
    timer.start
    SDL::Key.scan
    while event = SDL::Event2.poll
      case event
      when SDL::Event2::Quit
        exit
      when SDL::Event2::KeyDown
        $keydown = event.sym
        $any_keydown = true
      when SDL::Event2::KeyUp
        $keyup = event.sym
        $any_keyup = true
      end
    end

    input
    update
    draw
    @screen.flip
    SDL.delay( (1000 / @fps) - timer.ticks ) if timer.ticks < 1000 / @fps
  end
end

#title=(title) ⇒ Object

Sets the window title



265
266
267
# File 'lib/xibe.rb', line 265

def title=(title)
  SDL::WM.set_caption title, ''
end

#updateObject



305
306
307
# File 'lib/xibe.rb', line 305

def update
  scene_update unless @scene.nil?
end