• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Snippet Recording motion

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
This is a simple way of recording motion into an array to be used later. You could save this array and load in your game to use as raw material
for the motion of enemies or anything. Or you could could just toy around with it to see how much you can record into a tight space.

Here we use 65535 integers to record about 1092 seconds (A little bit more than 18min) of motion!

We play it back backwards from where you left off the last time recording as that is
a really nice way to get new kinds of motions.

Cerberus:
Strict
Import mojo2

Global data : Int[65535]    ' Create some space to record motion.
Global sp:Int = 32768       ' 65535 gives us 1092 seconds @ 60 fps. Set pointer in the middle.

Function Main:Int()
    New Game
    Return 0
End

Class Game Extends App

    Field canvas:Canvas

    Method OnCreate:Int()
        canvas=New Canvas            
        SetSwapInterval 1 ; SetUpdateRate 0
        Return 0
    End

    Method OnRender:Int()
        canvas.Clear 0,0,0,0
       
        ' Record ------------------
         Local xxx:Float = MouseX()
        Local yyy:Float = MouseY()
        If MouseDown(0) = False '  Record motion when not holding down mousebutton.
            canvas.SetColor 1,0,0
            If (Millisecs()/100) Mod 10 > 5 Then canvas.DrawText "Recording",0,0 ' Blink the text recording
            canvas.SetColor 1,1,1
       
            ' Save  position
            sp = sp - 1 ; data[sp] = ( (xxx Shl 14) + yyy)
            If sp = 0 Then sp = 65535 ' Make sure so stackpointer is within range
        ' --------------------------
        Else
        ' Playback ------ ' Playback motion (not from start but backwards from the moment you just recorded!) when not holding down mousebutton.
   
            ' Restore position
             xxx = (data[sp] Shr 14) & 16383 ; yyy = data[sp] & 16383 ; sp = sp + 1
             If sp = 65535 Then sp = 0 ' Make sure so stackpointer is within range
       
             canvas.SetColor 0,1,0
             canvas.DrawText "Playback",0,0
       
         ' -----------------------------
        Endif
   
        canvas.SetColor 1,1,1
        canvas.DrawRect xxx-16,yyy-16,32,32 ' Draw centered box
       
        canvas.Flush
        Return 0
    End

End
 
Last edited:
For completeness, here's a version that plays your sequence back as it was recorded, and loops it.

Cerberus:
Strict
Import mojo2

Global data : Int[65535]    ' Create some space to record motion.
Global sp:Int = 32768       ' 65535 gives us 1092 seconds @ 60 fps. Set pointer in the middle.
Global recording:Bool = False
Global length:Int = 0

Function Main:Int()
    New Game
    Return 0
End

Class Game Extends App

    Field canvas:Canvas

    Method OnCreate:Int()
        canvas=New Canvas           
        SetSwapInterval 1 ; SetUpdateRate 0
        Return 0
    End

    Method OnRender:Int()
        canvas.Clear 0,0,0.5,0
      
        ' Record ------------------
        Local xxx:Float = MouseX()
        Local yyy:Float = MouseY()
        If MouseDown(0) = True '  Record motion when not holding down mousebutton.
          If recording = False Then sp =32768 ; recording = True
            canvas.SetColor 1,0,0
            If recording = True And (Millisecs()/100) Mod 10 > 5 Then canvas.DrawText "Recording",20,0 ' Blink the text recording
            canvas.SetColor 1,1,1
            ' Save  position
            sp = sp - 1 ; data[sp] = ( (xxx Shl 14) + yyy)
            If sp = 0 Then sp = 65535 ' Make sure so stackpointer is within range
        ' --------------------------
        Else
        ' Playback ------ ' Playback motion (not from start but backwards from the moment you just recorded!) when not holding down mousebutton.
               If recording = True Then length = sp ; sp = 32768 ; recording = False
            ' Restore position

            If sp = length Then sp = 32768 ' Loop the last recording, whatever the length was.
            
             sp = sp - 1 ; xxx = (data[sp] Shr 14) & 16383 ; yyy = data[sp] & 16383
            If sp = 65535 Then sp = 0 ' Make sure so stackpointer is within range
             canvas.SetColor 0,1,0
             canvas.DrawText "Press to record, release for playback",20,0
         ' -----------------------------
        Endif
  
        canvas.SetColor 1,1,1
        canvas.DrawRect xxx-16,yyy-16,32,32 ' Draw centered box
        canvas.Flush
        Return 0
    End

End
 
This is interesting! Thanks for sharing your ideas and the general activity you bring to the forum.
When I read this it triggered some ideas about motion in games and maybe an animation editor.
- What about checking the data you recorded, if they could be interpolated with bezier curves or some other tweening function.
- What about recording one movement multiple times and calculate something like an average of all recordings to get to an ideal motion.
- What, if you could use those motions for particles or animations.
- In an animation editor similar to spriter or spine you could ommit a lot of the gui, if you could just influence the motion in real time. It's like going from old school 3d object creation going to sculpting objects, but for animation.
 
Thanks. Yes that's I'm looking into 3D actually.

I was thinking to do something like "additive" motion. You record something and then you add relative motion onto that multiple times as you wish That way you can "sketch" an animation.
 
Back
Top Bottom