Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

2 - Java 2D side scrolling Game Tutorial (part 1) - Scrolling background

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
34,035
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on May 13, 2010

In this first part of the video, I will be showing you how to make your background scrolling and make your character have the ability to move left and right with the proper scrolling background.

Let me know, if you have any questions, I will be happy to answer them.

SOURCE CODE:

Frame class: http://pastebin.com/w23N7uCH
Board class: http://pastebin.com/tLqg6EGj
Dude class: http://pastebin.com/BUW3vsja

  • likes, 2 dislikes

Link to this comment:

Share to:

Uploader Comments (MrJavaHelp)

  • if( (p.getX() - 1790) % 2400)

    I do understands what it does, but where does the value "2400" come from?

    Thanks for great tutorials btw :)

  • @Mattedatten You have the locations of two backgrounds being controlled (one by variable nx, one by nx2). The goal is to reset the value of nx and nx2 at a point to 0 (start of frame) and continue to increase their values, to simulate moving right.

    As you can see, when x is 590 the first bg resets, at 1790, 2nd bg resets, at 2990 1st bg resets then at 4190 2nd bg resets. Each are 1200 apart (size of frame) and each bg reset is 2400 apart (590,2990, etc). This is where the mod 2400 comes from.

Top Comments

  • Hey nice video you have posted. I am also working on a sidescroller, but using C/C++ instead!

    Now, I have an offtopic question, what program are you using to record your screen? I've tried a couple of them out there, but none of them is really fulfilling my needs!

    Thanks and keep up with the good work!

see all

All Comments (58)

Sign In or Sign Up now to post a comment!
  • im getting a error: Description Resource Path Location Type

    The method getY() is undefined for the type Dude Board.java /Terrarium/src/TerrariumPackag­e line 32 Java Problem help plz? :)

  • heyy i was kinda wondering im going to make a game like terraria what engine should i use?

  • ok so i fixed my errors from the last vid but now the back ground is not showing up can you help me asap pls

  • @schwartz0420 In the move() method, make the x-value increase steadily, like nx2 = nx2 + 2

    Then you make your dude fixed by removing his x-movement and you have a fixed dude moving on his own to the right (seemingly, it's actually the background that moves to the left).

    I'm doing that, but for some reason, every time the background loops two times, it stops looping once (tried adding a third, but then it stopped looping every third panel).

    Math + Saturday != working >.<

  • Great tutorial, but how would you make it to where the background scrolls automatically over time rather than linking it to movement? Much like it does in side scrolling space shooters, for example.

  • I guess one thing that made me overcomplicate things was my stubborn-ness to use a system similar to SNES, SEGA Genesis, Game Boy, NES, etc using a system of tiles - no winder my brain aches, this is much simpler.

  • Move the mic away a little bit from your face.

  • Its not working. Its only running the JFrame class. Please, please, please help!

  • @FloormanUK Somethings not synced

  • oh, didn't add the code, /E08h3wQ0

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more