I'm currently working on a side-scrolling jumping game. The object of the game is to press the correct key to jump a plat form. 1 would jump to the closest, 2 would jump to the farthest (and of course, more keys and more platforms).
The game starts with the cat on the far left side of the screen and only one platform will appear on the right side.
The user has to press the correct key to land on the platform.
I figured this out so far.
How do I scroll the screen so the cat and the platform it landed on is on the left side of the screen again?
I tried having it so when it collides with the platform, the object and the sprite will move to the X coordinate but it just jumps there. I want a smooth, following motion AFTER the cat safely lands on the platform.
Thanks in advance!
Never mind! I worked on some other things while waiting for an answer and then while looking for answers I found the answer.
I made an invisible sprite in the middle of the screen and pinned it to the playable sprite so the screen will follow the invisible sprite.
The way I do this is to have a separate sprite object called scrollObject to handle scrolling, and make a variable to control its x-offset (because it sounds like you want it to be not centered on the cat, but done so that the cat is on the side of the screen). Let's call that variable scrollOffset, and give it an initial value of whatever you want. You'll probably have to try a bunch of different amounts of offset to get it to look just right. Let's also make another variable called scrollSpeed so you can easily change how fast the 'camera' moves over to the cat and give it an intitial value, let's try 5 (again you'll want to test it out). Oh, and let's give the scroll object an instance boolean variable called doScroll, so we can tell it when we want it to do the scroll (initial value false). Then in events:
-on start of layout: set scrollObject X position to catSprite.x+scrollOffset
------scrollObject.X < catSprite.X+scrollOffset: set scrollObject X to scrollObject.X + scrollSpeed
------else: set doScroll to false
EDIT whoops I'm too late I guess, also perhaps I misunderstood what you wanted
Wow, thanks, mikehive. I solved the problem but if I can control the camera speed and when it move it, that's even better. thank you!
on a side note, I tried lerping with little knowledge of how to use it correctly but that didn't work. I set it to 0, cat.x, 0.5 but it never moved.. it actually didn't move at al when using any lerp input. hmm..
I had to change things around a little bit. Instead of moving the cat, everything else will move so the game can be endless rather than trying to figure out how to loop the background and all that jazz.
My issue right now is that I have platform zero (where the cat is at start of game), platform one, platform two, and then platform one again later. These four platforms will never change as they are used to get the player used to the game.
It's programmed in a way that when the cat jumps, ALL the platforms move to the left at the same speed; however, the second platform one (the third platform) is moving at a MUCH faster rate than the other platforms. Not sure why this is happening since it's not being addressed in a special manner at all.. any help?
Never mind. Just a simple coding error. Don't mind me!
Wish I could delete my posts sometimes!
I'm creating objects that's off screen with each press of key. The new objects are either platform one or platform two.
For some reason, when progressing through the first few steps, the created objects move much faster. Shouldn't they be following the same rules as the original platforms?
here's my file
https://www.dropbox.com/s/xb8modfxipt82 ... .capx?dl=0
Develop games in your browser. Powerful, performant & highly capable.
There is no visible pattern to this issue. I made the screen three times the width so I can see objects created but I see no pattern.
Jumping to the platforms one, two, or three has a random effect on the created objects. Sometimes they will stop when I land, sometimes some of them will stop, and sometimes none of them will stop. There is literally no pattern to this madness, er go, I can't see a solution. Some help?
Hmm, strange. Have you thought about simply repositioning the platforms that have gone off-screen to come round again, rather than creating new ones every time? That's generally good practice for infinite scrollers anyway, as repositioning existing objects is much more performance friendly than constantly deleting and spawning fresh objects.
Good idea, mikehive. I'll give that a try. But is it a bug that the spawned objects are not behaving like their parents? It just seems so weird.. especially when playing the game 20 times in a row and seeing no pattern whatsoever to when they would and would not move.