January 15, 2021, 06:34:00 PM

Author Topic: [bmx] Small animator by SystemError51 [ 1+ years ago ]  (Read 400 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Small animator by SystemError51 [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Small animator
Author : SystemError51
Posted : 1+ years ago

Description : I'm working on an online game right now, and the login screen required that tiny bit of subtle animation. I could not find anything here, so I quickly hacked a poor man's animator together.

You can define from and to where some image should animate, with what speed and what millisecond steps.

The parameters at the bottom allow you to change animation parameters at a later time, if so required.

Direction int's:
1 - Left
2 - Right
3 - Up
4 - Down

Create an animation like this:

yourObject.CA_CreateAnimation(yourImage , 20.0 , 20.0 , 100.0 , 100.0 , 40 , 2.0, 2, 4)

This will prepare an animation for yourImage at x:20 y:20 and destination x:100 y:100. Millisecond timer here is 40 (25 frames per second), animation speed per step is 2 pixels, direction is right and down.

I hope this makes sense...

Feel free to use :)


Code :
Code: BlitzMax
  1. ' ----------------------------------------------------
  2. ' ORION'S GATE
  3. ' A sci-fi MMORTS game.
  4. '
  5. ' depot/Tools/CoreAnimation.bmx
  6. ' A poor man's attempt at implementing a smooth
  7. ' animation framework as seen on OS X, for BlitzMax
  8. ' ----------------------------------------------------
  9.  
  10. Type CoreAnimation
  11.        
  12.         ' What should be animated
  13.         Field _ca_imageToAnimate                :TImage
  14.        
  15.         ' From where
  16.         Field _ca_startX                                :Float
  17.         Field _ca_startY                                :Float
  18.         ' To where
  19.         Field _ca_endX                          :Float
  20.         Field _ca_endY                          :Float
  21.        
  22.         ' Where are we now?
  23.         Field _ca_currentX                      :Float
  24.         Field _ca_currentY                      :Float
  25.        
  26.         ' Timer, and speed
  27.         Field _ca_timer                         :TTimer
  28.         Field _ca_animspeed                     :Float
  29.        
  30.         ' Directions to animate
  31.         Field _ca_horizontalDirection   :Int
  32.         Field _ca_verticalDirection             :Int
  33.        
  34.        
  35.         ' Create a new animation sequence
  36.         Method CA_CreateAnimation(image:TImage , startx:Float , starty:Float , endx:Float , endy:Float , timingStep:Int , animSpeed:Float, xAxis:Int, yAxis:Int)
  37.                
  38.                 _ca_imageToAnimate = image
  39.                 _ca_startX = startx
  40.                 _ca_startY = starty
  41.                 _ca_endX = endx
  42.                 _ca_endY = endy
  43.                
  44.                 _ca_timer = CreateTimer(timingStep)
  45.                 _ca_animspeed = animSpeed
  46.                
  47.                 _ca_currentX = startx
  48.                 _ca_currentY = starty
  49.                
  50.                 _ca_horizontalDirection = xAxis
  51.                 _ca_verticalDirection = yAxis
  52.                
  53.         EndMethod
  54.        
  55.        
  56.         ' Draw the animation. This will not clear the screen and assumes to be called in your draw loop
  57.         Method CA_DrawAnimation()
  58.                 If _ca_currentX <> _ca_endX Or _ca_currentY <> _ca_endY
  59.                         If WaitTimer
  60.                                 If _ca_horizontalDirection = 1
  61.                                         _ca_currentX = _ca_currentX - _ca_animspeed
  62.                                 EndIf
  63.                        
  64.                                 If _ca_horizontalDirection = 2
  65.                                         _ca_currentX = _ca_currentX + _ca_animspeed
  66.                                 EndIf
  67.                        
  68.                                 If _ca_verticalDirection = 3
  69.                                         _ca_currentY = _ca_currentY - _ca_animspeed
  70.                                 EndIf
  71.                        
  72.                                 If _ca_verticalDirection = 4
  73.                                         _ca_currentY = _ca_currentY + _ca_animspeed
  74.                                 EndIf
  75.                         EndIf
  76.                 EndIf
  77.                
  78.                 DrawImage _ca_imageToAnimate , _ca_currentX , _ca_currentY
  79.                
  80.         EndMethod
  81.        
  82.        
  83.         ' Adjust parameters
  84.         Method CA_SetStartX(newstartx:Int)
  85.                 _ca_startX = newstartx
  86.         EndMethod
  87.        
  88.         Method CA_SetStartY(newstarty:Int)
  89.                 _ca_startY = newstarty
  90.         EndMethod
  91.        
  92.         Method CA_SetEndX(newendx:Int)
  93.                 _ca_EndX = newendx
  94.         EndMethod
  95.        
  96.         Method CA_SetEndY(newendy:Int)
  97.                 _ca_EndY = newendy
  98.         EndMethod
  99.        
  100.         Method CA_SetHorizontalDirection(dir:Int)
  101.                 _ca_horizontalDirection = dir
  102.         EndMethod
  103.        
  104.         Method CA_SetVerticalDirection(dir:Int)
  105.                 _ca_verticalDirection = dir
  106.         EndMethod
  107.        
  108. EndType


Comments :


SystemError51(Posted 1+ years ago)

 I forgot to mention that you have to use
Code: [Select]
CA_DrawAnimation()in your main draw loop (or where ever required) to actually draw the animation. [/i]

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal