none
Making a clean animation with LDScrollbars RRS feed

  • Question

  • Hey all! 

    I have been working on a game lately, and I ran into an issue. I am trying to keep an object in the center of the scrollbars. But when I move the object at high speeds, the object will glitch a bit. The higher the speed, the more it glitches.

    I wrote this sample program to show it:

    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 500
    GraphicsWindow.DrawRectangle(250,250,500,500)
    
    Ball = Shapes.AddEllipse(10,10)
    x = 400
    y = 600
    dx = 2.8
    dy = 3
    
    LDScrollBars.Add(1000,1000)
    LDScrollBars.Visibility = "False"
    
    While 1 = 1
      Program.Delay(5)
      x = x + dx 
      y = y + dy
      
      Shapes.Move(Ball,x,y)
      LDScrollBars.VerticalScroll = y - 250
      LDScrollBars.HorizontalScroll = x - 250
      
      
      If x > 740 Or x < 250 Then
        dx = -dx
      EndIf
      If y > 740 Or y < 250 Then
        dy = - dy
      EndIf
      EndWhile

    I'd appreciate any help! :D


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11



    Tuesday, February 3, 2015 10:14 PM
    Answerer

Answers

  • Uploaded a test version with new method LDPhysics.FollowShape, call this after adding shape to physics engine.

    EDIT - Some nice effects, so modified again to control X and Y following separately, LDPhysics.FollowShapeX and LDPhysics.FollowShapeY.

    EDIT2 - Such a good idea for scrolling type games, I added to test version LDPhysics.BoxShape to keep a shape within an imaginary box of the graphicsWindow as it moves within the world.
    Monday, February 9, 2015 7:34 PM
    Moderator

All replies

  • Not sure, this is what you want. But for the same look and feel, i would use a transparent Rectangle Shape and move this 'rect' around in-/outside of the GW.

    ...

    GraphicsWindow.BrushColor = "Transparent"
    rect = Shapes.AddRectangle(500,500)
    Shapes.Move(rect, 250,250)

    ball = Shapes.AddEllipse(10, 10)

    ....


    Tuesday, February 3, 2015 11:00 PM
    Answerer
  • I would for this program, But this is just an example program to show the issue. :D

    I can't do that on the other program.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, February 4, 2015 1:06 AM
    Answerer
  • Not perfect, but my attempt within Small Basic limitations of double buffering.

    While 1 = 1
      Program.Delay(5)
      x = x + dx 
      y = y + dy
      
      Shapes.Move(Ball,x,y)
      LDScrollBars.VerticalScroll = y - 250
      LDScrollBars.HorizontalScroll = x - 250
      
      LDGraphicsWindow.ResumeUpdates()
      LDGraphicsWindow.PauseUpdates()
      
      If x > 740 Or x < 250 Then
        dx = -dx
      EndIf
      If y > 740 Or y < 250 Then
        dy = - dy
      EndIf
    EndWhile


    Wednesday, February 4, 2015 6:33 PM
    Moderator
  • Believe it or not, I already tried that :D

    It works pretty well, but with large programs it was very jerky and sometimes made a weird flickering effect.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, February 5, 2015 4:42 AM
    Answerer
  • Mmm,

    Interestingly when I slow it down I see the effect, and it seems to be related to certain positions of the scroll region, so the previous suggestion I made isn't the whole story.

    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 500
    GraphicsWindow.DrawRectangle(250,250,500,500)
    
    Ball = Shapes.AddEllipse(10,10)
    x = 400
    y = 600
    dx = 20
    dy = 20
    
    LDScrollBars.Add(1000,1000)
    LDScrollBars.Visibility = "False"
    
    While 1 = 1
      x = x + dx 
      y = y + dy
      
      LDScrollBars.VerticalScroll = y - 250
      LDScrollBars.HorizontalScroll = x - 250
      Shapes.Move(Ball,x,y)
      Program.Delay(100)
      
      LDGraphicsWindow.ResumeUpdates()
      LDGraphicsWindow.PauseUpdates()
      
      If x > 740 Or x < 250 Then
        dx = -dx
      EndIf
      If y > 740 Or y < 250 Then
        dy = - dy
      EndIf
    EndWhile

    So, perhaps when x-250 < 0, the scoll only goes to 0, but circle still shown at x.

    So I tried the following to prevent a value for x,y that results in scroll bar movement being outside allowed limits.  Perhaps this is the issue.

    GraphicsWindow.Width = 500
    GraphicsWindow.Height = 500
    GraphicsWindow.DrawRectangle(250,250,500,500)
    
    Ball = Shapes.AddEllipse(10,10)
    x = 400
    y = 600
    dx = 20
    dy = 20
    
    LDScrollBars.Add(1000,1000)
    LDScrollBars.Visibility = "False"
    
    While 1 = 1
      x = x + dx 
      y = y + dy
      
      If (x < 250) Then
        x = 250
        dx = -dx
      ElseIf (x > 750) Then
        x = 750
        dx = -dx
      EndIf
      If (y < 250) Then
        y = 250
        dy = -dy
      ElseIf (y > 750) Then
        y = 750
        dy = -dy
      EndIf
      
      LDScrollBars.VerticalScroll = y - 250
      LDScrollBars.HorizontalScroll = x - 250
      GraphicsWindow.Title = "("+(x - 250)+","+(y - 250)+")"
      Shapes.Move(Ball,x,y)
      Program.Delay(100)
      
      LDGraphicsWindow.ResumeUpdates()
      LDGraphicsWindow.PauseUpdates()
    EndWhile

    Thursday, February 5, 2015 7:05 PM
    Moderator
  • That works better, but there is still the flickering issue. I noticed it happens on slower PCs.

    It seems that every time I use LDGraphicsWindow.PauseUpdates I get the flickering issue. :(


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, February 5, 2015 7:33 PM
    Answerer
  • I can't see the effect now, but putting the delay and updates in this order may help - seems most stable for me.

      Program.Delay(5)
      LDGraphicsWindow.ResumeUpdates()
      LDGraphicsWindow.PauseUpdates()

    Apart from this I will need an example that shows the problem - my guess it is all tied up with system draw updates and tricky to change much without rewriting SmallBasicLibrary.dll and on slower PCs they may be struggling to keep up with the redraws in some way so the delay in this position may help.

    Thursday, February 5, 2015 7:50 PM
    Moderator
  • I have upload a new test version where I attempted to flush visual buffers in the Updates() methods. 
    Thursday, February 5, 2015 9:24 PM
    Moderator
  • Hey, do you know of any reason why the latest version would break my game? All of the physics objects were unresponsive and acted almost like there was gravity. (There wasn't)

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, February 5, 2015 11:08 PM
    Answerer
  • Do any of the samples show the same problem?

    I did make a change to allow individual shapes to have separate gravity effects but for my tests it seems ok.

    Try setting the zero gravity as the first LDPhysics command.  I think this should work, but I will try to fix.

    EDIT

    Uploaded with gravity bug hopefully fixed

    Thursday, February 5, 2015 11:37 PM
    Moderator
  • The gravity bug is fixed :D

    The wheels are being weird though, they have a whole lot less power and turn speed.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Friday, February 6, 2015 12:13 AM
    Answerer
  • I think this is an improvement that I added at the end of the tire additions (in current main build as well as beta test build) to make the tire force and torque units consistent with all other forces and torques.

    The base units are 10 pixel/m.  So a force of 100*mass is an acceleration of 10m/s/s, and a torque of 0.1*Inertia is 0.1 radian/s/s.  In my example I used a 30 pixel car (3m) and could apply a known realistic acceleration and report velocities in correct units of m/s.

    Friday, February 6, 2015 9:04 AM
    Moderator
  • Makes sense!

    BTW, Is there any way I could center the Physicswindow on an object? That would fix the scrollbar problem I'm having.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Saturday, February 7, 2015 5:28 PM
    Answerer
  • The physics window just uses the same Shapes.Move functions during the updae after the physics engine does its calcs.

    If one shape is always centered, then you wouldn't use the scrollbars, have you considered the LDPhysics.PanView command like you did in the dirtbike game?

    Saturday, February 7, 2015 6:44 PM
    Moderator
  • Thats what I was asking :D Sorry if I wasn't clear.

    I meant is there a way to keep the pan view centered on an object. I the dirtbike game, I couldn't get it perfect and the window would slowly drift off to one side. I really don't want to make something that works "Most the time" :)


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Monday, February 9, 2015 2:32 AM
    Answerer
  • Uploaded a test version with new method LDPhysics.FollowShape, call this after adding shape to physics engine.

    EDIT - Some nice effects, so modified again to control X and Y following separately, LDPhysics.FollowShapeX and LDPhysics.FollowShapeY.

    EDIT2 - Such a good idea for scrolling type games, I added to test version LDPhysics.BoxShape to keep a shape within an imaginary box of the graphicsWindow as it moves within the world.
    Monday, February 9, 2015 7:34 PM
    Moderator
  • Works great!! Nice and smooth.

    Just BTW, what am I doing wrong with this? :D

    Timer.Tick = Explode
    Timer.Interval = 2000
    
    While 1 = 1
      Program.Delay(10)
      LDPhysics.DoTimestep()
    EndWhile
    
    Sub Explode
      LDPhysics.AddExplosion(200,200,400,0,"Red")
      EndSub


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, February 11, 2015 5:40 AM
    Answerer
  • Try this:

    Timer.Tick = Explode
    Timer.Interval = 2000
    
    While 1 = 1
      Program.Delay(25) '25 ms is default Physics engine time step, so is a good delay to keep time consistent
      If (doExplode) Then
        LDPhysics.AddExplosion(200,200,400,0,"Red")
        doExplode = "False"
      EndIf
      LDPhysics.DoTimestep()
    EndWhile
    
    Sub Explode
      doExplode = "True"
    EndSub

    The timer event is on a separate asynchronous thread and the physics engine doesn't like being modified as it is doing its calcs.

    Wednesday, February 11, 2015 10:49 AM
    Moderator
  • Okay, makes sense.

    Hey, Is there any way to apply friction to a turning tire? Because if I turn a tire and let co of the controls, it just keeps turning.


    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Wednesday, February 11, 2015 10:07 PM
    Answerer
  • Try the Straighten property in SetTireProperties.

      properties["Straighten"] = 5
      LDPhysics.SetTireProperties(car,properties)
    PS In the latest test upload I rewrote the pan, follow and box methods (basically pan the images in the display rather than move them in the physics engine).  I have tested in my cases and think all works as before, let me know if you see any changes apart from smoother and removes some occasional strange effects that were there e.g. a pile of bricks could fall during panning or objects moved ouside the AABB and get frozen - not now).  Also fixed a bug that gave an exception in your dirtbike game (one of the cases I test with).

    Wednesday, February 11, 2015 11:32 PM
    Moderator
  • Cool!

    Found another issue :(

    For some reason the positioning is off in the physicswindow. Every time I get position, It gets it off of the corner of the screen. But when I set it, It sets it off of the global corner. Here is a picture showing what I mean:



    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11


    Friday, February 13, 2015 6:32 PM
    Answerer
  • Do you have the latest test upload? - this could be due to the changes I made and modified a couple times to improve the panning etc

    Do you have a simple test case to show it?

    EDIT

    I did code it so that the position is the screen position, not the world position - to be compatible with previous versions - this was by design to keep ALL user positions input and output based on the current display regardless of scrolling.

    I could change this but would like to keep it properly consistent either way.


    Friday, February 13, 2015 9:37 PM
    Moderator
  • Uploaded a test version where all positions (input and output) remain in world coordinates apart from GetShapeAt which really is most useful in screen coordinates - let me know which you think is best if it works as expected.

    Also added GetPan method to help with interacting with screen coodinates like adding a shape at the mouse position in a panned screen using this offset.

    Friday, February 13, 2015 10:29 PM
    Moderator