Strict Standards: Non-static method phpbb_feed_factory::init() should not be called statically in /home/jacius/rubygame/forums/feed.php on line 66
[phpBB Debug] PHP Notice: in file /feed.php on line 171: Cannot modify header information - headers already sent by (output started at /feed.php:66)
[phpBB Debug] PHP Notice: in file /feed.php on line 172: Cannot modify header information - headers already sent by (output started at /feed.php:66)
Rubygame Forums 2010-09-24T23:18:19+00:00 2010-09-24T23:18:19+00:00 <![CDATA[Displaying Background and Objects]]>
So you'd think this would let me keep my background image on the screen and have this second, mostly transparent surface updating over it, but the background just looks black when I run the program. I currently have the background drawing again on each frame, but that slows down the program considerably.

I'm wondering what the "theory" is behind drawing and updating backgrounds and the objects over them. What's the best approach?

Here's the applicable part of my code. A second class that inherits from this one supplies the name of the map, a couple objects, and turns @active to true.

class Map
  def initialize(name)
    @background = Rubygame::Surface.load("#{name}.png")
    @w = @background.w
    @h = @background.h
    @surface =[@w, @h])
    @surface.colorkey = [100, 100, 100]
    @screen_rect =, 0, $screen.w, $screen.h)
    @objects = {}
    @active = false

  def draw
    return if @active == false
    @surface.fill([100, 100, 100])
    @background.blit($screen, [0, 0], [0, 0, @w, @h]) #This makes the program run slower, but it's the only way it seems to work...
    @surface.blit($screen, [0, 0], @screen_rect)
  def draw_objects
    return if @active == false
    @objects.each_value do |obj|
  def draw_background
    @background.blit($screen, [0, 0], [0, 0, @w, @h])

Okay, I discovered a screen.fill in my main script. Removing it allowed the background to be seen, but everything was being drawn on top of the old stuff, creating hundreds of little guys all over the screen.

I've been thinking, and it seems that I will need to draw the background to the screen on every frame, whether I want to or not. But why does it affect the program's performance so much? The surface is a simple .png file, 1000 x 1000 pixels, stored in an instance variable. What am I doing wrong?

Statistics: Posted by Fridgecrisis — Fri Sep 24, 2010 11:18 pm