QUOTE (azdesign @ Jun 23 2012, 10:57 AM)

Hello everyone, nice to meet you,
I made a custom class to display character portrait in RPGMaker XP Here is the class :
CODE
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 :
CODE
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
Your
while loop is the root of all evil

Try use these methods, instead:
1. in the intiialize method, add this variable declaration:
CODE
@wait = 5
@step = 0
@anime_x = 0
@anime_y = 0
@forward = true
@repeat = 0
@wait_count = 0
2. just modify this method your class:
CODE
def animate(x,y,step,delay)
@repeat = 2
@wait = delay
@wait_count = delay
@anime_x = x/step
@anime_y = y/step
@step = step
@forward = true
end
3. create this method in your class
CODE
def update
if @repeat > 0 #cycle
if @wait > 0 #wait procedure
@wait -= 1
return
end #wait end
if @step > 0 #step procedure
if @forward
move(@anime_x,@anime_y)
else
move(-@anime_x,-@anime_y)
end #end forward
@step -= 1
else
@forward = !@forward
@repeat -= 1
if @repeat < 0 #repeat occurence
@repeat = 4
@wait = 3*@wait_count
else
@wait = @wait_count
end #end repeat
end #end step
else
animate(x,y,steps,delay)
end #end cycle
end #end method
where
x,y, step and
delay are the variables you have to set at your will.
4. You must trigger an event in parallel process (or just a common event, as you wish... you can even modify Scene_Map's update, if you desire to...) and put this line into a
call script:
CODE
$(variable).update
where $(variable) is your public instance object name...
and it should magically work (well, it should)

I just hope not to have done mistakes...
If so, just post

I hope this can help...
Jens
This post has been edited by Jens of Zanicuud: Jun 24 2012, 06:13 AM