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 http://rubygame.org/forums/feed.php?f=4&t=156 2010-09-24T23:18:19+00:00 http://rubygame.org/forums/viewtopic.php?t=156&p=617#p617 <![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.

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

  def draw
    return if @active == false
    @surface.fill([100, 100, 100])
    draw_objects
    @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)
  end
 
  def draw_objects
    return if @active == false
    @objects.each_value do |obj|
      obj.draw(@surface)
    end
  end
 
  def draw_background
    @background.blit($screen, [0, 0], [0, 0, @w, @h])
  end
 
end


EDIT--
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


]]>