[Solved] ScrollTo behavior works but sprite goes off screen

Get help using Construct 2

Post » Mon Dec 29, 2014 11:16 pm

I added the ScrollTo behavior to the Player sprite. So now the screen follows the Player as it moves. Scrolls smooth which looks really good, but the Player moves off the viewable screen before the layers start to scroll. So then you can't see the Player anymore. Is there a way to adjust the camera centering, or something, so the scrolling starts before Players gets off the screen edge?
Last edited by locohost on Tue Dec 30, 2014 1:32 pm, edited 1 time in total.
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Mon Dec 29, 2014 11:17 pm

Can you share your capx?
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Tue Dec 30, 2014 1:19 am

The docs say ScrollTo behavior causes the viewport to scroll with and center on the object with ScrollTo behavior. This is definitely not true. Well, partially true, it scrolls with the object but completely looses centering. The object moves faster and leaves the view port behind.

Is the issue that the ScrollTo behavior does not work with a Physics object moving by applied angular force?
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Tue Dec 30, 2014 2:18 am

When you have two sprites with both scroll to behavior enabled at the same time it wont work. Ensure that you have only one scroll to behavior enabled.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Tue Dec 30, 2014 3:17 am

scrollto does work. It's just very hard to troubleshoot without seeing the problem firsthand.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Tue Dec 30, 2014 1:28 pm

Thank you very much for the replies guys. I definitely do appreciate and need the advice :)

I was able to work around the ScrollTo issues. Yes it has issues when you're trying to follow a Physics body sprite. It does not keep the screen centered as the docs say. Perhaps when using simple 8-Dir movement it works, but not with a Physics body. I'm using C2 release r190 (64 bit) as I type this.

To work around this I created a second "Camera" sprite. Set ScrollTo behavior on this Camera. I then placed the Player sprite in the center and the Camera in the center of the Viewport. Player and Camera both have center origins. The Camera is double the size of the Player. I doubt the Camera size matters, but thought I'd include. On every System tick event, I set the Camera.X/Y to the Player.X/Y * 2. Yes, Player.X/Y times 2. This workaround keeps the Physics body Player sprite perfectly centered on each Viewport X/Y axis as it is forced around. This fixes ScrollTo so it works as it actually should.

If you've ever used Phaser, it's FollowCamera behavior works perfectly with any kind of sprite. The Construct 2 ScrollTo behavior should also. This being said, Construct 2 is still much easier than using Phaser 8-)
Last edited by locohost on Tue Dec 30, 2014 3:00 pm, edited 17 times in total.
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Tue Dec 30, 2014 1:34 pm

kossglobal wrote:When you have two sprites with both scroll to behavior enabled at the same time it wont work. Ensure that you have only one scroll to behavior enabled.


The docs say that you can set ScrollTo on multiple sprites. The Viewport will (will try) to center between the two sprites. I didn't try but I doubt this works.
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Tue Dec 30, 2014 2:45 pm

Quick update: I just exported my Construct 2 game to "Android". Opened up the exported folder in "Intel XDK" IDE, built, ran on my Note 3 phone (attached by USB) and it looks and works perfectly! Thank you, thank you, thank you to Scirra and Intel! :)
B
13
S
4
Posts: 280
Reputation: 1,578

Post » Tue Dec 30, 2014 3:14 pm

locohost wrote:
kossglobal wrote:When you have two sprites with both scroll to behavior enabled at the same time it wont work. Ensure that you have only one scroll to behavior enabled.


The docs say that you can set ScrollTo on multiple sprites. The Viewport will (will try) to center between the two sprites. I didn't try but I doubt this works.


I didn't make myself clear I guess. I meant that It wont work properly because, as you said the camera will try to follow the center between the objects which I believe is not what we usually want. :)
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Tue Dec 30, 2014 5:05 pm

kossglobal wrote:
locohost wrote:
kossglobal wrote:When you have two sprites with both scroll to behavior enabled at the same time it wont work. Ensure that you have only one scroll to behavior enabled.


The docs say that you can set ScrollTo on multiple sprites. The Viewport will (will try) to center between the two sprites. I didn't try but I doubt this works.


I didn't make myself clear I guess. I meant that It wont work properly because, as you said the camera will try to follow the center between the objects which I believe is not what we usually want. :)


Ok then yes I agree :)
B
13
S
4
Posts: 280
Reputation: 1,578


Return to How do I....?

Who is online

Users browsing this forum: BackendFreak, farsen, kellehk, lahbach, newt, R0J0hound, TRMG and 23 guests