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 / Vertical scrolling and increasing speed

Author
Message
Juxton
9
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 27th Feb 2015 21:08
I've been trying to work this stuff out for a month now, and have finally had enough, so I thought I'd ask here.

The only way I've figured out how to vertically scroll my background is to simply move the image along the Y axis, but is there a better way?

I tried adapting the code from Space Shooter, but it appears that the UV coding only works for the X axis. Is there something that works on the Y axis?

I also want the scrolling to speed up every 30 seconds, but the only way I can figure out to do that is to code each 30 second period by itself (ie, 30, 60, 90, etc.), and I increase the speed only slightly each time, so that will be a lot of coding.

At the risk of looking like an idiot, I'll include the coding I use for this bit.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Feb 2015 16:28 Edited at: 28th Feb 2015 16:29
A couple of comments...

Don't set your speed to 0.75. Work out how far you want to travel in 1 second, and calculate it every frame. Some devices will be running at 60FPS, others (low-end) at 30FPS, and others may vary wildly. Thus, your game plays differently for all users.

Lets say you want to scroll 45 units per second. Save 45 as a variable at the top of the program, outside the game loop.

defaultScroll# = 45

Each frame, calculate y# as:

y# = defaultScroll# * getFrameTime()

This bit only works once, for 30 seconds. It also assumes you are playing only one game, getSeconds()is the start of the app., not the start of each new game.



try something like this. Firstly, record the start time of the game:

gameStart# = timer()

Then, calculate the game time each loop:

gameTime# = timer() - gameStart#

Then use this to perform a dynamic calculation to increase the time every 30 seconds. In this code, elapsedTime is an integer:

elapsedTime = gameTime# / 30
defaultScroll# = defaultScroll# + ((defaultScroll# / 3) * (elapsedtime - 1))


I assume from your code that you are increasing the scroll speed by a third of the original value.

Quidquid latine dictum sit, altum sonatur
Juxton
9
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 28th Feb 2015 23:06
Thanks very much! I'll try all this.

Sometimes I think I'm not the kind of beginner this program was designed for, because I'm having a hard time getting the hang of things. I get frustrated when there's something I need to use (like a timer) but there's not code that is designed specifically for my exact need. Obviously unless I want to do something someone else has already done, I probably won't find that sort of code. But it still frustrates me because I have a hard time adapting what code I do find.

And then, though I may get the game to do what I want (like coding each increase in speed separately) I know that there's a better way to do it, and, like you said, it may not work on every device.

Anyway, I could go on and on about my frustrations, but at least I'm not giving up because of them.

Again, thank you!
Juxton
9
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 28th Feb 2015 23:30
I'm sorry for my lack of understanding, but do I put all the code after y# = defaultScroll# * getFrameTime() in the loop? Because nothing is happening whatsoever. When I include all but defaultScroll# = 45 in the loop, the screen doesn't move.

Like I said, I'm worse than a beginner. I understand what your code means along with each part of it, but maybe I'm placing some of it in the wrong place, or maybe I need to add something to it that you may have thought was self-explanatory so you didn't put it?

I also tend to take instructions too literally, so there's probably more to it that I'm missing. This is how my code for this looks right now.



The screen scrolls at the correct beginning speed, but it never increases speed.

What am I missing, here?
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 1st Mar 2015 16:22
gameStart# = timer()

should be outside the loop otherwise gametime will always be 0

life's one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Mar 2015 20:59 Edited at: 1st Mar 2015 21:01
I haven't tested, but Smallg is right. The code should look morelike this:



Glad to know you're not getting frustrated enough to give up. Sometimes it's easier to write down the pseudo code on paper before you start. Scribble down the steps and think it through before you touch the keyboard

Quidquid latine dictum sit, altum sonatur
Juxton
9
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 1st Mar 2015 22:13
Thanks for the help, guys, but it's not scrolling at all using the code snipping BatVink last posted.

It's cool, though. I'm going to start from the beginning now that I know more about different coding to use and proper locations of lines of code. It's really just a game to practice coding. A simple game that only consists of your character jumping to different ledges of an infinitely scrolling tower that speeds up every 30 seconds, nothing that I intend on trying to sell. I think I'm trying to make it more complicated than it needs to be.

Plus I'm going to force myself to go through Hands On AGK2. I say force because I'm one of those guys who hates doing activities that I can't see will apply to my game. But I'm sure there's a lot of info in there that will help me do this.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Mar 2015 10:20
I didn't test my code above, just wrote it straight into the post. I think this is the concept you are looking for. If it is, you should be able to apply it to your project...



Quidquid latine dictum sit, altum sonatur
Juxton
9
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 5th Mar 2015 00:39
BatVink

That is absolutely perfect, thank you! I'll admit that I know next to nothing about "global" and such, that's why I'm going through the book.

Again, thank you!

Login to post a reply

Server time is: 2024-11-25 18:38:10
Your offset time is: 2024-11-25 18:38:10