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 / A question about 2D side scrolling

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Nov 2017 09:10
What methods do you use or recommend? I have started on the path of scrolling UVs on the sprites, but I have now remembered that you need power of 2 images.
For HD, this means a 2048 wide image squashed down into a 1920 wide sprite.
I also have to consider the height, which can differ for the different layers in the parallax effect. I'll need a lot more squashing and jiggery pokery to make it fit.
Anyone recommend I continue down this route, or consider moving sprites or another method?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Jambo B
15
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 5th Nov 2017 11:13 Edited at: 5th Nov 2017 11:16
BatVink: I'd go for tiles as moving sprites if I were you, reusing them when they scrolled off the edge. If you kept all of the tiles' images on the same Atlas, they could all be drawn at the same time, speeding things up a bit.
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 5th Nov 2017 12:47
It's funny you should ask.
I started putting together some parallax scrolling code during some quiet time at work yesterday.

You're right about the power of 2 limitation so you are better off (as Jambo said) using tiled sprites and resetting them when they go off the screen.

I've attached the code I created for parallax scrolling. It works as it is but it's not complete.
Good stuff:
1) It automatically calculates the number of sprites required to tile horizontally
2) Layer speeds are calculated automatically but can be changed. Either individually, all together or you can change the relative difference in speed of each layer

Needs adding:
1) It is not frame-rate independent but that is an easy thing to do.
2) You can only scroll left or right, you can't jump to a particular location in the world but again this is an easy addition.

You will obviously need to change the "main.agc" file to use your sprites and your display set-up and not include my engine but I've included it to demo how to set p and run the scrolling system.

Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Nov 2017 13:11
Very useful, thanks both of you.
I think I should make the effort to make it tile based. I did it many moons ago in DBPro, I recall it wasn't too difficult once you have the mechanics in place for recycling sprites.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 5th Nov 2017 21:54
I use tiles (sprites) all placed and set view offset to scroll around. For parallax I use separate smaller background maps and move all those tiles based on where the player is - works a charm. My game works out how big the maps are and so calculates the parallax accordingly - saves me having to do anything custom per level.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 11th Nov 2017 14:21
I made a tile of size 256x256, set SetImageWrapU and SetImageWrapV on it, set the size I wanted , then made it roll with SetSpriteUVOffset. For virtual resolution width 1920 I used bkg sprite width of 2560 or so. To accomodate some devices having wider screens and without borders going over..

Login to post a reply

Server time is: 2024-11-24 06:07:26
Your offset time is: 2024-11-24 06:07:26