Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Need some scrolling help ....

Author
Message
ProfVersaggi
12
Years of Service
User Offline
Joined: 6th Apr 2012
Location: Maastricht Netherlands / Chicago, USA
Posted: 26th Nov 2012 13:55
I'm trying to properly scroll the viewport around my world as I follow an object in motion (in this case a ship), but I'm having troubles. I am using Physics, if that changes anything ...

I'm using the SetViewOffset() command, but it keeps placing the boat object in the top left corner and then it prevents it from moving at all.

What I need to do is when I propel my ship through the water, and *only* as I approach an edge of any screen, the screen viewport automatically scrolls a specified amount to accommodate the part of the map in question, be it up, down, left or right (by a certain amount).

However, I'd also like to define real boundaries of the map and enforce those some how, but I'm not exactly sure how that would get done.

Does anyone have any experience with this?

Many thanks in advance....

----
From the Desk of Prof Versaggi ...
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 26th Nov 2012 16:16
Some code would help, but I assume you are passing the ship x,y cords to the SetViewOffset ? if so it will move to the top left as you have indicated. If you want it in the center of the screen you need to pass the ship cords minus half the screen width (for x) and half the screen height for y (thats not taking the ship size into account. I have not had to setup a camera trap yet but will be in the coming week.
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 26th Nov 2012 18:42
How are you managing your map? Are you loading it all in at once, or building it as you move around?
I have knocked this bit of code up to show you one way to scroll around using viewoffset.


It's not what you are asking for but perhaps you would prefer a smooth scroll to a push scroll one? No physics but it should easily be possible to change it to a physics based movement routine.

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 26th Nov 2012 19:07 Edited at: 26th Nov 2012 19:10
First of all, for barriers I would setup dummysprites with static physics applied.

About the scrolling, you want the screen to move when the ship gets near the edge of the screen, correct?
I would create a function that moves the camera to a target coordinate with desired speed and smoothness. Then keep a check on when when the ship is close to a screen edge with perhaps WorldToScreenX/Y. So that when "WorldToScreenX(ship) > ScreenWidth - 20" or something, then increase the Camera Target X that you have set up in above mentioned function. In that function you would have something like "if camera target x > world width then set camera target x to maximum value" so that you don't go further than your barrier.

Let me know if I need to be more specific

EDIT: The reason your boat is in the top left corner I would guess is because you are setting view offset to the ship's x/y values which would move the camera together with the boat and keep it in that corner. Try setViewOffset(shipX - (halfOfScreen), shipY - (HalfOfScreen) for this approach.

My hovercraft is full of eels

Login to post a reply

Server time is: 2024-05-02 00:46:21
Your offset time is: 2024-05-02 00:46:21