- 0
How to properly runs animation without interfering with main loop
Asked by
azdesign
-
Recently Browsing 0 members
No registered users viewing this page.
Asked by
azdesign
No registered users viewing this page.
Hello everyone, nice to meet you,
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 endCreate 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[/color] Graphics.update end endI 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 has suggestion for better logic for playing animation ?
Share this post
Link to post
Share on other sites