Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Memor-X on August 05, 2012, 03:54:14 am

Title: Making an image move in a curve
Post by: Memor-X on August 05, 2012, 03:54:14 am
i've been working on my ARC intro animation and trying to get some of the images to circle around the arc logo

i'm making the images move my changing their x or y values in script, this is a line of code i use for a strait line


image.x += (frame - start) * multiplier


image is an instance of Bitmap.new
frame is a variable i'm using for frame counting
start is the value of the frame the image starts moving on, so say i wanted to wait 50 frames before an image moves, i would normally hardcode this
multiplier is just use to speed up a image moving across, otherwise i would have to wait 100 frames for a image to move across 100 pixels, if i make it 2, it'll just take 50 frames

not really the best way to animate but it works, that's all i need at the moment

now, natully, i can't use the line for going around curves unless i want a huge switch/case statement or stuck loads of elsif's, so is there a way i can get an image to move in a curve much like what i've done with a strait line, it doesn't need to be a big curve, as long as i can use them eventually to make a circle
Title: Re: Making an image move in a curve
Post by: diagostimo on August 05, 2012, 06:23:56 am
it would be rather easy to generate a curve pattern, all you would have to do is condition it between an x and y point and increase/decrease values from there, take this example to generate a full circle:

#top to right
if @x >= 5 && @x < 10 &&  @y < 5
  @x += 1
  @y += 1
#right to bottom
elsif @x >= 5 && @y >= 5 && @y < 10
  @x -= 1
  @y += 1
#bottom to left
elsif @y >= 5 && @x <= 5 && @x > 0
  @x -= 1
  @y -= 1
#left to top
elsif @x >= 0 && @x < 5 && @y <= 5
  @x += 1
  @y -= 1
end

you could write the condition in many ways, just as long as it contains it from leaving the given path, the only problem is the complexity of the path your giving it, more curves = more conditions
Title: Re: Making an image move in a curve
Post by: Memor-X on August 07, 2012, 12:54:44 am
that's even better, let see, with a bit of working i can use it to generate curves by stopping it at particular frames