How do I Create Faster and Smoother Auto Platform Movement?

0 favourites
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • So here is my event and layout

    Explanation :

    1. The black sprite is the "camera" which whenever I touch left/right side of the screen, this sprite will move and it has scroll to behaviour also set to invisible

    2. The Green boxy sprite is the character which must be chased by the screen, this sprite will move automatically

    Now the question is, this thing works well on HTML5 preview using Chrome, Opera and FF but when converted to Android via Ludei CocoonJS, it's laggy and the auto movement is not working well, sometimes it stucks on the platform

    Any suggestion? Thanks in advance

  • bump, it's still horribly laggy

  • bump again!

  • One thing I would change is how often you update the text3 field. I notice on mobile devices there is a considerable slow down if I update a text field every tick which is what your code shows its doing. I would instead suggest to update the text field every 1 second or so to help performance. also I believe set position on the green sprite is also more cpu consuming than just simulating pressing left/right. Same goes for the black sprite/camera... I would look into a plugin called "moveto" (created by rexrainbow) to move it across the screen... Based on the the code you've shown i would change those things first and try again

  • One thing I would change is how often you update the text3 field. I notice on mobile devices there is a considerable slow down if I update a text field every tick which is what your code shows its doing. I would instead suggest to update the text field every 1 second or so to help performance. also I believe set position on the green sprite is also more cpu consuming than just simulating pressing left/right. Same goes for the black sprite/camera... I would look into a plugin called "moveto" (created by rexrainbow) to move it across the screen... Based on the the code you've shown i would change those things first and try again

    Thanks for the input, gonna post the result soon

    Change the text score to update every 1 sec, the performance seems a little better now

  • submitted twice, duh

  • So, here is the updated eventsheet

    Is that the right way to use moveto?

    CPU usage cut down from 40% to +-20%

    Haven't tested it on Android, gonna report soon

    Ignore the 5th event, forgot to delete it

  • Based on what your doing there I may have giving wrong advice on using move to.. (if it works the you want then i would keep it) I would suggest for sprite6 (for smoother movement) that you give it the 8 direction behavior (since its not a platform object) and in the behavior properties for that sprite turn off default controls (this way the keyboard wont trigger the move)... then when touching sprite8 or sprite7 simulate moving left or right as desired... That should give smoother movement and better control. But cpu usage should be about the same i think as using moveto since they basically work the same way.

  • troublesum

    Where did you get that info, moveto is basically a x += x * dt (Or somethin' like that), prolly' slower than x = a, but the difference isn't noticeable , it's normal that sometimes your sprites get stuck, you are moving by increments of 8, thus going on top of the player, that breaks the physics and collision detection is like Wuuut? Or this could just happen in mobile, maybe because the frame rate gets choppy and the movement slower also no they don't work the same way, platformer has to simulate gravity, acceleration, deceleration, check for keys and such, and that is way heavier than just doing a delta-time calculation

    You could always use moveto, but if you are comfortable with math, you could just multiply every position value by DT, then the blocks should move the same speed regardless of the fps

  • I've tested it on Android using cocoon js compiler and it's a lot smoother using Moveto also it doesn't works using 8movements, it simply refused to move

    Thanks btw troublesum and Whiteclaws

    Btw, is there any other auto path / predefined movement trick for such thing?

    I mean something like I only need to set the path and it will always move like that whatever the circumstances

  • Whiteclaws After running some tests your definitely correct (though the cpu difference as you said was negligible) i ran 500 sprites moving across a blank screen which uses est 9-10% cpu using set pos and uses est 9.5-10.5% using simulate... Not sure why I though it was faster.. just seemed like my game runs smoother with simulate.. optical illusion i guess.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's normal it runs smoother, it's not an illusion, platformer multiplies the position values by dt, so that the object will move at the same speed regardless of the fps, otherwise it would slow down if fps was under 60, you can solve that by down something like

    X = x + 8 (or the increment value you want) * dt

  • Allright, is it ok to ask another question?

    This time, it's a flappy bird clone using Kenney arts

    That are the screenshoots

    Perform well on chrome, only using 20% of CPU usage, compiled to APK using cocoonjs and it's laggy on the start, gradually become better after 2 or 3 rock passed

    Any idea to optimize it?

  • As I said, try my FPS trick, it should do the job

  • As I said, try my FPS trick, it should do the job

    this one?

    X = x + 8 (or the increment value you want) * dt

    What is dt? Deltatime?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)