move image, stop, continue moving query

BlitzMax Forums/BlitzMax Beginners Area/move image, stop, continue moving query

DannyD(Posted 2013) [#1]
I'd like to move an image horizontally to the middle of the screen, stop and wait x seconds and then continue moving off the screen.

matibee posted a nice chunk of code :
SuperStrict

Type lerpStage
	Field startTime:Float
	Field endTime:Float
	Field startPos:Float
	Field endPos:Float
	
	Function Create:lerpStage( st:Float , et:Float , sp:Float , ep:Float )
		Local ls:lerpStage = New lerpStage
		ls.startTime = st
		ls.endTime = et
		ls.startPos = sp
		ls.endPos = ep
		Return ls
	End Function
	
	Method Position:Float( time:Float )
		Local t:Float = time - startTime
		t :/ endTime - startTime
		Return startPos + t * ( endPos - startPos )
	End Method 
	
End Type 
	
Type LerpAnimator
	Field stages:TList
	Field time:Float
	Field lastMS:Float
	
	Function Create:LerpAnimator( stage:lerpStage )
		Local la:LerpAnimator = New LerpAnimator
		la.stages = New tlist
		la.stages.addlast( stage )
		Return la
	End Function
	
	Method addStage( stage:lerpStage )
		stages.Addlast( stage )
	End Method
	
	Method Update()
		time :+ 0.001 * Float(MilliSecs() - lastMS)
		lastMS = MilliSecs()
	End Method
	
	Method Position:Float()
		For Local ls:lerpStage = EachIn stages
			If ( ls.startTime <= time And ls.endTime >= time )
				Return ls.Position( time )
			End If
		Next
		Return lerpStage( stages.Last() ).endPos
	End Method
	
	Method Start()
		lastMS = MilliSecs()
		time = 0
	End method
End Type 
		
		
Graphics 800 , 600

Local animator:LerpAnimator = LerpAnimator.Create( lerpStage.Create( 0 , 1 , 800 , 300 ) )
animator.addStage( lerpStage.Create( 1, 6 , 300 , 300 ) )
animator.addStage( lerpStage.Create( 6 , 7 , 300 , - 200 ) )
animator.Start()

While Not AppTerminate()
	
	Cls
	
		DrawRect animator.Position() , 200 , 200 , 200
		DrawText animator.Position(), 0, 0
		
	Flip 1
	
	animator.Update()
	
Wend 


This is similar but probably over complicated for me. Any simple examples ? Thanks.


DannyD(Posted 2013) [#2]
Am I right in thinking that the image will move along the x axis ?

Repeat 
DrawImage(logo,x,400)
x = x +1

Until x=1000



DannyD(Posted 2013) [#3]
Scot's code is of great assistance.
http://www.blitzbasic.com/Community/posts.php?topic=58104#646343


col(Posted 2013) [#4]

Local animator:LerpAnimator = LerpAnimator.Create( lerpStage.Create( 0 , 1 , 800 , 300 ) )
animator.addStage( lerpStage.Create( 1, 6 , 300 , 300 ) )
animator.addStage( lerpStage.Create( 6 , 7 , 300 , - 200 ) )



is where you need to look.

the lerpStage.Create( 0, 1 , 800, 300 )

sets a stage to start at time 0 and finish at time 1 in seconds, start at value of 800 and end at a value of 300. This will adjust the value from 800 to 300 in the time frame of 0 to 1 seconds. The time frame is taken from when .Start is called. You can add stages to be carried out by adding more lerpStage(s).


col(Posted 2013) [#5]
So you would add stages to your requirements, so to adjust the example to start from the left and move the rect right to the center, wait 5 secs then move off screen to the right you would have...

Local animator:LerpAnimator = LerpAnimator.Create( lerpStage.Create( 0 , 1 , -200 , 300 ) ) ' MOVE FROM OFFSCREEN LEFT TO THE CENTER IN ONE SECOND
animator.addStage( lerpStage.Create( 1, 6 , 300 , 300 ) ) ' WAIT 5 SECS AT THE SAME POSITION
animator.addStage( lerpStage.Create( 6 , 7 , 300 ,  800 ) ) ' MOVE FROM THE CENTER OF THE SCREEN TO OFFSCREEN RIGHT HAND SIDE IN ONE SECOND