YolkfolkThe Dizzy Fansite 0 logged in0 playing
Community discussion

Smooth Scrolling Demonstration

Started by Noggin the Nog on 24 July 2015 • 16,823 views

25 posts
#55490
So I've had a couple of free days this week and began to wonder how to do smooth scrolling in DizzyAGE, much like you find in The Last Hero and Night at the Museum. After a bit of work I came up with a technique which, though not quite as good as those games, works pretty well and I thought I'd share it on here in case anyone wants to use it.

What I've done is make a little demo - just a small map without any puzzles - so people can download it and see.

You can download the "data" folder from DropBox here:
https://www.dropbox.com/s/mojafni7bdwi7hh/smooth_scrolling_demo.zip?dl=0

Aside from the scrolling, I've modified Dizzy's movement to make that smoother too. If you're interested in any of the code, you'll find it all in the game.gs, handlers.gs and movement.gs files.

EDIT: There's also a new function in the util.gs file.

A quick a technical point too: The big trick to the technique is that I've changed the game's frame rate (G_FPS) from 36 to 48, and increased Dizzy's frame delay (P_DELAY) to 4. This means that whilst Dizzy's motion appears unchanged, he now moves (horizontally) four pixels every four frames, instead of four every three. This really simplifies the coding for the scrolling and made it possible to smooth up Dizzy's movement too. However, these things won't work properly if G_FPS and P_DELAY aren't changed, so you can't just add the scrolling code to an existing game without making a bunch of other changes. Obviously, increasing the FPS will make everything else (animations, AI) run a third faster.

But please feel free to use the demo as a template or to contact me if you have any questions etc. I'm getting a little cold on making new games (doing the graphics is interminable) but I'm happy to help other people. :smile:
👍 0
#83211
Nice one! That definitely looks nicer. To my mind though, Dizzy moves just a little too slow. I'm making a scrolling game at the moment, and I think if anything I was looking to speed him up. Fantastic Dizzy has a large map, but you can cross it in just a few minutes. But I'd imagine it has to do with graphic limitations, so instead I'm just going to make warp points. (Is this why you did too?)

You've really helped me out with reaching the end of the screen though so thanks for that! I wanted to make Dizzy continue to the edge like you've done and I couldn't work it out. Just changing the room's properties is something I'd never have thought of. I tried using colliders to change G_Viewportmode, and it was weird; it would work once and then get all jerky, or it would stop working altogether.
👍 0
#83214
You can always speed Dizzy up by increasing the G_FPS further, it's just everything else gets sped up too. The frame rate is set in the GameStart Handler.
👍 0
#84297
Recently I've been playing the early apogee games and the first Rick Dangerous game and noticed that they all use room scrolling techniques so thought it about time I learned the basic rules of scrolling. Unpaking most scrolling games and trying to figure the technique just made my brain hurt. So, on the off chance did a 'advanced' search and found your demo Simon. Thank you so much for doing this as it seems that I might finally be able to get to grips with this.

One thing though, the bottom co-ordinate of the map is noted as 536, which is actually 8 pixels up from the bottom of the 'room', but assume that it's not relevant as the area is a block, so Dizzy can never actually reach it.
👍 0
#84298
That's great, I'm glad to hear it's being used.

Yes, there's no need to set the edge of the scrolling area to the edge of a room, you can put it anywhere. Using room variables is just a convenient way to attach the properties to the map, say if you want to make two or more separate areas linked by doors or something, you can set different room properties in each area.

Let me know if you've got any questions. :smile:
👍 0
#84300
Thanks Simon, I'm sure I'll have lots when I start playing around with the demo and start adding stuff.
👍 0
#84301
I was actually never able to work this out. How to set the edge of the scrolling screen, I mean, so Dizzy can walk all the way to the edge. I'm not sure why. I went through it with a fine tooth comb. It's not really hampered me much, but it always bugs me a little when I can't solve a coding problem!
👍 0
#84303
I might be talking out of my backside Andy, but from what I gather from Simon's demo is that the room properties act as a sort of 'frame' for the whole map, so that once the r/h or l/h edge is displayed in the hud the map stops centering round Dizzy's co-ordinates, but still allow him to continue walking in the same direction..
👍 0
#84304
That would be exactly right. You need to just set the room properties (left, right, top, bottom) to the x and y coordinates of the edges of your game area.
👍 0
#84370
Got a bit of a problem Simon. Been trying to incorporate the 'scrolling' aspects into a test template that also includes a lot of stuff I've previously built into some of my games ie, running, turning, fading, climbing etc.

Now the game is falling over as it starts as it is failing to find something in the following line
in the handler after update:

left = RoomGet(roomx,roomy, R_LEFT) + roomw/2;

I've included the R_LEFT, R_RIGHT, R_TOP etc in the defines in the def file and set the room properties on the map.

Also included the G_ROOMXSTORE in the defines (just in case it was the previous line in the handler script that was iffy).

I'm sure I've done everything such as changing the frame and delay rate in the start up , added all the defines and the set screen coding in game and handler and replaced the movement.gs file with the one in the demo.

Is there anywhere you can point me to check further?
👍 0
#84371
Hi Steve. Sorry, I just want to make sure it's nothing obvious before I dive into the code - are roomx, roomy and roomw defined in the function?

I'm thinking something might have gone missing if you copy/pasted the code. Also, could you tell us what sort of error you're getting?
👍 0
#84372
I don't think it's a big coding issue Simon as the demo works fine (even when I've added status checks to turn off and on the vertical scrolling and change the background tile) - always think it best to play around with something to get to grips with it! So made sure I knew what needed to be added or altered to the handler, movement and game files when setting up a new 'test game' to explore further.

It's a -1 issue in the HandlerGameAfterUpdate function that appears before the game starts as the engine can't find the R_LEFT define. Roomx, roomy, roomw & roomh are defined prior to the

left = RoomGet(roomx,roomy,R_LEFT) + roomw/2;

command line. But ...the R_LEFT = 0, etc defines are included in the def.gs file so the engine should not be having a -1 issue especially as the def.gs file is a straight copy from the demo.

My brain hurts!
👍 0
#84373
Do you mean a BADTYPE error that comes up right after the game has loaded?

All I can think of in that case is that there's a duplicate #def somewhere in one of the script files or maybe some rogue ///s cancelling out the line.

Also - a random thing I found out recently - in the dizzy.gs file, the def and gamedef files have to be at the top of the list for the defines to work in the other scripts.

That's everything I can think of for now.
👍 0
#84375
"Thunk, thunk, thunk" - that's me banging my head! Decided to scrap the test game, so took one of my 'standard' game templates and deleted all the extra stuff involving movement. Then copied the def, gamedef, movement files, the scrolling and backdrop coding from both the game and handler files of the demo. Altered the frame rate to 48 and delay rate to 4, added a tile for the background and thought let's go.

The game opened, but the backdrop wouldn't load (it is dynamic 240 x136 and the ID is the same as the bgd define in the update backdrop) Then noticed that Dizzy was a tad jittery and over the course of two and a half screens walks out of sight as he is moving faster than the game is scrolling.

Now comes the interesting part, tried to restart and got the loading screen, pressed enter and got "EXCEPTION_INT_DIVIDE_BY_ZERO at address 0x4294c8" Aaaaaaghhhh!!!!

OK, I'll do one more test, I'll replace all the coding in my template with everything in the demo - and alter the door functions and the scroll reading functions. If that works then it must be a conflict with some of my extra coding that I always include.
👍 0
#84377
I had a look through the scripts for my demo today and discovered there's a function necessary for the scrolling hiding in the util.gs file.

I don't think it's got anything to do with the problems you're having - it only affects the y-scrolling, but you'll need to include the function (called PlayerFallCheck()) in your game.
👍 0
#84378
Thanks Simon, handy to know. As it was I switched all the coding in my 'template' test game with your demo and of course it works fine. Now to slowly add the extra stuff I put into a game to see what happens - I might have to come back to you for advice at some point as the climbing code and the run fast code reset the custom movement of the character. Thanks for your help.
👍 0
#84464

I revisited this and made a few updates, ironed out some kinks.

In particular, I discovered that my smooth movement code didn't work with moving platforms, so I've corrected that.

Also, I've added a feature where Dizzy shares the motion of horizontally moving platforms, so you don't have to walk along as the platform moves. :cool:  

Check it out: https://www.dropbox.com/s/mojafni7bdwi7hh/smooth_scrolling_demo.zip?dl=0

👍 0
#84466
Thanks Simon, downloaded and ready to 'blow my mind' (damn, I must still be in the 1980s) :lol:

nb - it'll be interesting to see how you've done Dizzy moving on platforms - I never used AI, but created a move function (x or y plus a few pixels and reset) and added a collider on the platform that did the same to Dizzy, so that he could still leap off when necessary.
👍 0
#84653
I've only just seen this, but I did something with moving platforms in Pirate Ship Dizzy.
👍 0
#85857
Hi Simon, been having another go at this recently, but still not having much success. However, it made me wonder why Alex included the basic viewport coding in DizzyAge if you needed to add so much extra coding to make it work properly ...so as I have a (slightly) better understanding of what's going on in the coding (although not much success in implementing it {dizzy}:frown: ) I set the viewport function to 1 in the startup of one of my earlier games to see what happened and discovered that the movement works fine but the view is cockeyed as you also view the adjacent screens as the map centers around Dizzy. So, took out the Y scrolling line and it is almost perfect for horizontal scrolling - just needed to have a block halfway across the rooms at the extreme ends of the map to stop it scrolling past the border (Did try setting the room properties but the engine just laughed at me!).

However, you can amend the coding in the 'HandlerGameAfterUpdate' function to check the status of a dynamic object outside the game area, ie if status is 1 add the room = and X coding, if status is 2 add the room = and Y coding and if status is 3 add both. Therefore if status = 0 the scrolling isn't turned on. Then just added suitable Open/Close room commands or suitably placed colliders to change the status and did a test by having the top of a hill halfway up the screen before turning on the vertical scrolling to go down the hill and turn if off halfway down the bottom of the hill screen which worked fine.

As this may be a 'reasonable but long winded' solution for me to deal with scrolling for future games I'm now going to try and add your 'background' movement and see what happens (already did a test when using your template to switch backdrop from night to day and back again and it worked).

Plus, I might be 'ready' to crack open Colin's 'A Pirates' Life game and see how he did the scrolling ...but it will probably just make my brain hurt again. :wall:
👍 0