Moving while doing loop animation in RPGMaker
        Posted  
        
            by 
                AzDesign
            
        on Game Development
        
        See other posts from Game Development
        
            or by AzDesign
        
        
        
        Published on 2012-06-23T07:54:29Z
        Indexed on 
            2012/06/23
            9:26 UTC
        
        
        Read the original article
        Hit count: 346
        
ruby
|rpg-maker-xp
I made a custom class to display character portrait in RPGMaker XP Here is the class :
class Poser
  attr_accessor :images
  def initialize 
    @images = Sprite.new
    @images.bitmap = RPG::Cache.picture('Character.png') #100x300
    @images.x = 540 #place it on the bottom right corner of the screen
    @images.y = 180
  end
end
Create an event on the map to create an instance as global variable, tada! image popped out. Ok nice. But Im not satisfied, Now I want it to have bobbing-head animation-like (just like when we breathe, sometimes bob our head up and down) so I added another method :
  def move(x,y)
    @images.x += x
    @images.y += y
  end
  def animate(x,y,step,delay)
    forward = true
    2.times {
      step.times {
        wait(delay)
        if forward
          move(x/step,y/step) 
        else
          move(-x/step,-y/step)
        end
      }
      wait(delay*3)
      forward = false
    }
  end
  def wait(time)
    while time > 0
      time -= 1
      Graphics.update
    end
  end
I called the method to run the animation and it works, so far so good, but the problem is, WHILE the portrait goes up and down, I cannot move my character until the animation is finished.
So that's it, I'm stuck in the loop block, what I want is to watch the portrait moving up and down while I walk around village, talk to npc, etc.
Anyone can solve my problem ? Or better solution ? Thanks in advance
© Game Development or respective owner