Hello and I'm trying to make my own game engine in Java. I have completed all the necessary ones but I can't figure it out with the TileGame class. It just can't scroll. Also there are no exceptions. Here I'm listing the code.

Show us only the relevant part of the code and tell us what you've tried already. Maybe even why you think it isn't working.
–
Byte56♦Mar 22 '12 at 2:01

3

The reason these details are important is so that we know you understand the code and can narrow down where the problem area resides. Otherwise, you might be someone who is using code they don't understand and asking someone else to fix it so you can pass it off as your own. Not to mention, that is a lot to look through... (Not saying you are doing this, just mentioning why it isn't good practice to approach these questions this way.)
–
AndrewAchillesMar 22 '12 at 3:01

1

You don't seem to be changing the Offset values at all...
–
thedaianMar 22 '12 at 3:07

1

I can see the problem but as others mentioned you likely don't understand the code so just a hint: go through your scroll offset calculation line by line and figure out exactly what each does and why is it there. That's a basic debugging skill which you have to master if you're going to become a programmer. Figuring out exactly what each part of your code does is also a good idea.
–
GileadMar 22 '12 at 3:13

1 Answer
1

Hopefully you have solved this yourself by now, if not here is some help to get you there.

Debugger

That program you're using to type all your code in to? It's not just for typing code in and pressing "play". It's an IDE (Integrated Development Environment). This means it contains many tools to help you develop, one of those tools is the debugger. I suggest you read more about debuggers here.

How do you use the debugger?

It's going to depend on your IDE of choice (they likely contain very similar debuggers, but just go with it). For Java there are a few major ones: Eclipse, Netbeans and more. Regardless they all have some similar features. One of the most powerful features is breaking, breaking can happen automatically from an exception (as I'm sure you've seen), or it can happen manually via the use of breakpoints. For situations like yours, breakpoints are your best friend. They will allow you to stop execution of your code at a specific point, and examine the state of your program at that time.

How do you use breakpoints?

Again, this is IDE specific. Commonly it's a right click off to the left side column of the code window and selecting "Enable breakpoint". Yes, it's that easy. After setting a breakpoint, you'll start your program in debug mode. This mode lets the IDE know that it should pay attention to breakpoints and other debug features. Now, when the code execution gets to the point in your code where you set your breakpoint, it stops, and turns control over to you. This is awesome. You can now view what variable values are, many IDEs let you execute code snippets to see their result against the current state of your program, change values and more! This is SO powerful. Breakpoints rock.

Now that your program execution has stopped, it's not dead. It's waiting for you to tell it what to do next. Again, you have some powerful options. You can continue execution as normal, you can step into functions, step out of functions or step over line by line. Amazing. It's often useful to set a breakpoint at the beginning of a function, then step through the code line by line, seeing the variables change and following the execution of the code. The line by line stepping is by far the coolest way to follow the execution of your program.

Now, I hope you've read the above, followed some of the links, and looked up how to perform the actions described using your IDE of choice. If you've gotten this far, I'll offer you a further hint. Set a breakpoint on this line: if (follower!=null){ check your values. Is follower null? How about scrollHorizontally and scrollVertically, are they both true? Now, step line by line, watch how your OffsetX and OffsetY values change as you change them around, around in a full circle ;)