How do I Create Faster and Smoother Auto Platform Movement?

Get help using Construct 2

Post » Tue Jun 03, 2014 1:03 pm

So here is my event and layout

Image
Image

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 :D
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 9:31 am

bump, it's still horribly laggy
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 4:04 pm

bump again!
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 4:24 pm

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
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Wed Jun 04, 2014 4:34 pm

troublesum wrote: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 :D

Change the text score to update every 1 sec, the performance seems a little better now
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 5:13 pm

submitted twice, duh :cry:
Last edited by ijoin on Wed Jun 04, 2014 5:22 pm, edited 1 time in total.
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 5:18 pm

So, here is the updated eventsheet

Image

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 :lol:
B
8
S
2
Posts: 203
Reputation: 1,169

Post » Wed Jun 04, 2014 5:23 pm

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.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Wed Jun 04, 2014 5:52 pm

@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
Last edited by Whiteclaws on Wed Jun 04, 2014 6:00 pm, edited 2 times in total.
B
42
S
17
G
17
Posts: 2,247
Reputation: 17,461

Post » Wed Jun 04, 2014 5:53 pm

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 :D

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
B
8
S
2
Posts: 203
Reputation: 1,169

Next

Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, FabianB and 31 guests