The Daily Click ::. Forums ::. Klik Coding Help ::. Help with scrolling
 

Post Reply  Post Oekaki 
 

Posted By Message

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 15:53:46 -

Hey guys, i want a simple way to do smooth scrolling, and a good scrolling engine. So i can have a camera object, and a scroll to object. Where it speeds up if its too far away, and slows down as it gets to it. I also need to be able to block off scrolling in certain directions if i need to, like, it wont scroll left or right, but it can up and down.
I hope you get the idea.. i have done this kind of thing before, but it was a huge work around for how im sure its ment to be done, it had about 6 groups for itself and LOADS of code... im sure there is a simple way, has anyone got a scroll engine they are willing to share, just so i can take a look and learn from it. Or just some help would be hot!

Thanks guys !

 
dont make me divide by zero...

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 17:01:19 -

Hey don't worry if you can't do all of those things, just some ideas would help! Il be very greatfull =

 
dont make me divide by zero...

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
3rd December, 2010 at 17:20:41 -

hay guiz show me how to do this hurry hurry

ok? ok

Edited by GamesterXIII

 
n/a

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 17:29:13 -

Ok... Maybe I was a lil' too RAAGE, I do apolagise... In your own time guiz 

 
dont make me divide by zero...

GamesterXIII



Registered
  04/12/2008
Points
  1110

I am an April Fool
3rd December, 2010 at 17:41:52 -

Give an example of what you need.

 
n/a

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 17:47:09 -

Ok, a scrolling engine that is very versatile, and smooth. By this I meen, you can choose where you want it to scroll to, and turn off left, right, up or down scrolling If u wanted. And by smooth I meen not ridged snap to style scrolling. To cut a long story short, the style that the underside uses. 

 
dont make me divide by zero...

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
3rd December, 2010 at 18:00:52 -

What you're asking for is basically quite simple.


Originally Posted by Zephni
So i can have a camera object, and a scroll to object. Where it speeds up if its too far away, and slows down as it gets to it.


You indeed use an camera object to control the scrolling. The speed depends on the distance, there are all sorts of formulas you can use for calculating the scrolling speed by using the distance. For example an easy one: speed = distance/2

Scrolling towards an object is done by scrolling towards the position of that object.


Originally Posted by Zephni
I also need to be able to block off scrolling in certain directions if i need to, like, it wont scroll left or right, but it can up and down.


This does require some more programming like using groups as you mentioned. Although I would probably just use some flags of an object for the four directions: left, right, up and down. Then when such a value is true (flag is on), scrolling in that direction is enabled. If the value is false (flag is off) scrolling in that direction is prohibited. Checking for those flags should happen in the correct scrolling event (e.g. scrolling left, is the flag on? all right scroll!).


Originally Posted by Zephni
has anyone got a scroll engine they are willing to share, just so i can take a look and learn from it.


Not sure if the peasants are going to share this, but the camera system does have a scroll to function which is used to switch between the two characters.
http://www.create-games.com/download.asp?id=6610
Furthermore in a platformer type of game which scrolls horizontally and vertically the scrolling automatically stops at the edges of the level.


Originally Posted by Zephni
Or just some help would be hot!


I hope this post will help you a bit. You might to do the coding yourself, but that's practically all there is.

Have fun coding

P.S. I need a decent, working, code tag for quoting or should I use the code blocks for quoting partial posts?
Edit: quoting just doesn't show itself in the preview.

Edited by Jenswa

 
Image jenswa.neocities.org

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 18:29:31 -

Hey Jenswa! Thanks for replying.
See i have tried doing the distance/2 equation, but its a little too fast, and if you divide by 10 or somthing, it works well but wont get prescisly to the spot u want it too when you stop moveing because your working with numbers below 1.0

So i have something like this:

+ If camera's position is different to "scroll to" object
- set XMovement(Camera) to = (camera pos - scroll to pos)/10

But when i stop moveing it will be a good 10 pixels off where it should be because 9/10 pixels is 0.9

Do you see my point?

 
dont make me divide by zero...

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 18:29:32 -

I accidently double posted

Edited by Zephni

 
dont make me divide by zero...

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
3rd December, 2010 at 19:00:04 -

Yes, I know.

You might want to add some extra code for calculating the camera speed instead of directly using the calculated speed value, that way you can adjust your speed value for these cases. This is the easy way to fix this problem. Another possibility is to round up your division result, so it will make those mini steps of 1 pixel you need when you're at and below 10 pixels distance.

Don't believe I can come up with a better or more elegant solution than to round up the result.

 
Image jenswa.neocities.org

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 20:20:55 -

how do i round up a value. i tried useing ceil() for ceiling value, and round() for rounding a value but neither seem to of worked..
Now im testing by doing distance/2 so when it gets to 1 pixel away the camera's movement would be 0.5 ... but its not working... so maybe im not useing the right function to round it up? any ideas?

 
dont make me divide by zero...

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
3rd December, 2010 at 21:29:56 -

Ok i have figured out a work around to get that to work... Now how about the cutting off the left/right or up/down scrolling... remembering that it needs to scroll to the center of the screen, and then cut off the directional scrolling...

 
dont make me divide by zero...

Jenswa

Possibly Insane

Registered
  26/08/2002
Points
  2722
5th December, 2010 at 15:09:49 -

Well, if you're scrolling with the camera, it's just an object that can be looked into certain positions. If you only want to scroll between x=100 and x=200, then use the correct events/statements like this in pseudo code:

if x >= 100 and x < 200 set x position to some value in between of 100 and 200

You can enable or disable this code by adding a flag to the condition. When you want to use it, you can enable it with this flag. So it will only scroll in between. Once that's working you can change the 100 and 200 into variables that you will control, something like: stopx and distance. If stopx = 100 and distance = 100 then you will receive the statement of the mentioned example above.

Happy programming

 
Image jenswa.neocities.org

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49567

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
5th December, 2010 at 15:23:50 -

Pretty much all scrolling engines can be done with formulas.

Create a separate camera object, always center the camera on the camera object then..

Easy linear scrolling:
Always-
-Set X of camera object to X("camera")+(X("Player")-X("Camera"))*0.3+min(max((X("Player")-X("Camera")),-1),1)
-Set Y of camera object to Y("camera")+(Y("Player")-Y("Camera"))*0.3+min(max((Y("Player")-Y("Camera")),-1),1)

Smooth "Screens" type scrolling:
Always-
-Set X of camera object to X("camera")+((X("Player")/640)*640)-X("Camera"))*0.3+min(max(((X("Player")/640)*640)-X("Camera")),-1),1)
-Set Y of camera object to Y("camera")+((Y("Player")/480)*480)-Y("Camera"))*0.3+min(max(((Y("Player")/640)*640)-Y("Camera")),-1),1)

For this scrolling method you can change the 640 and the 480 to whatever the screen size is for your game. You could even add in some other kinda tricky math to make it scroll before the player reaches the side of the screen.

Another cool trick is to switch between scrolling modes using trigger objects. Make tricky platforming sections easier to play with a static screen.

Coolness!

 
n/a

Zephni

My other cars a Balrog

Registered
  17/10/2007
Points
  4019

Has Donated, Thank You!VIP MemberSonic Speed
5th December, 2010 at 18:17:37 -

I have sections that change the camera type already, i have already done that in my platform style levels. Im starting to get some idea's of how to do it. when you get into a area it changes the camera type, and then sets the scroll to object to the middle of the screen so the screen is locked, and then when you leave the screen it goes back to normal scrolling. But i was wondering the best way to have it if i wanted to cut off just one side, or two sides.. I could do it, coz i already have before, but it seems like a huge work around for what could be quite simple.

Thanks for both of your comments they both helped

 
dont make me divide by zero...
   

Post Reply



 



Advertisement

Worth A Click