How to make my game scroll more smoothly ?

Hello! I'm new at Java, however I have some programming experience.
I would like to make a tile engine. On the following link is an example of what I have so far:
[link-->|http://members.home.nl/bramdenhond/testjava/]
If you move your mouse over the area, the world scrolls.
However, I don't think it scrolls smoothly enough.
In the tutorial I was following, this technique was recommended for double-buffering:
        //** Update - Method, implements double buffering */
        public void update (Graphics g)
              // initialize buffer
              if (dbImage == null)
                    dbImage = createImage (this.getSize().width, this.getSize().height);
                    dbg = dbImage.getGraphics ();
              // clear screen in background
              dbg.setColor (getBackground ());
              dbg.clearRect(0, 0, this.getSize().width, this.getSize().height);
              //dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              // draw elements in background
              dbg.setColor (getForeground());
              paint (dbg);
              // draw image on the screen
              g.drawImage (dbImage, 0, 0, this);
        }For the timing, I'm using a Thread, as recommended in the tutorial:
         public void start ()
              // define a new thread
              Thread th = new Thread (this);
              // start this thread
              th.start ();
          public void run ()
              // lower ThreadPriority
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              // run a long while (true) this means in our case "always"
              while (true)
                    // repaint the applet
                    repaint();
                    try
                          // Stop thread for 20 milliseconds
                          Thread.sleep (2);
                    catch (InterruptedException ex)
                          // do nothing
                    // set ThreadPriority to maximum value
                    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
           }I was wondering if someone if this is indeed the best approach, and if there are
any alternatives.
Thanks!

Hi all,
I've changed this source code so I can move the character from bottom to up but scrolling background is up to bottom. How I can change this class for scrolling background from up to down and not viceversa?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.awt.Image;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
public class JAniDemo {
  private BufferedImage biBackground = null;
  private Toolkit tk;
  private JFrame f;
  JAniDemo(){
    tk = Toolkit.getDefaultToolkit();
    f = new JFrame("AniDemo 1.0");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    loadBackground("C:\\image.png");
    myPanel p = new myPanel(biBackground);
    f.add(p);
    f.pack();
    f.setVisible(true);
  private void loadBackground(String fn){
    Image im = tk.getImage(fn);
    MediaTracker mt = new MediaTracker(f);
    mt.addImage(im,0);
    try{
      mt.waitForID(0);
      biBackground = new BufferedImage(800, 641, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = biBackground.createGraphics();
      g2.drawImage(im, 0, 0, null);
      g2.dispose();
    }catch(InterruptedException e){
      System.out.println(e.toString());
  public static void main(String[] args) {
    new JAniDemo();
  class myPanel extends JPanel implements ActionListener{
    private BufferedImage background;
    private BufferedImage bi = null;
    private int upperCorner = 0;
    int width;
    int height;
    myPanel(BufferedImage bg){
      super();
      background = bg;
      width = background.getWidth()/2;
      height = background.getHeight();
      bi = background.getSubimage(0,upperCorner,width,height);
      setPreferredSize(new Dimension(width, height));
      Timer t = new Timer(25, this);
      t.start();
    public void actionPerformed(ActionEvent e){ 
      upperCorner -= 1;
      if(UpperCorner >= height) UpperCorner = 38;  // adjust to make rollover seemless
      bi = background.getSubimage(0,UpperCorner,width,height);
      repaint();
    public void paintComponent(Graphics g){
      g.drawImage(bi, 0, 0, this);
}Please see this changes of original source code:
bi = background.getSubimage(0,upperCorner,width,height);
width = background.getWidth()/2;
if(UpperCorner >= height) // for vertical
upperCorner -= 1; // for up to down scrolling
Can you help me? Thanks.
Regards.
Edited by: Rapworld on Jun 9, 2010 11:19 AM

Similar Messages

  • How to make other people image more beautiful

    how to make other people image more beautiful?

    Well I think this is a good topic that has a lot of possibilities, I understand the OP is seemingly being vague but I think perhaps it might be grammatical more then lack of content.
    <br />
    <br />But there are techniques and different approaches to capturing the best qualities of the subject especially those of the human subject.
    <br />
    <br />cjmah
    <br />
    <br />the best way to go about this is post an image that you took of someone that you think can be improved and we can share with you techniques and ideas about equipment that you might like to have to help you achieve what you want to achieve.
    <br />
    <br />Her you save the image as a jpeg about 600 to 700 pixels on the longest length the go to this link
    <br />
    <br />http://www.pixentral.com you follow the instructions for uploading the file then you copy the text in the top text field and paste it into you message before you post it.
    <br />
    <br />Make certain you copy all the text including the link you know from and including this
    <a all="" the="" way="" to="" and="" including="" this="" /></a>
    <br />
    <br />It is a good subject.

  • How to make a Flash site more searchable

    Hi all,
    I was wondering how to make a Flash site more searchable in
    search engines. I'm guessing it is with meta tags, can anyone tell
    me which meta tags or if there are any other hints or tricks.
    Thanks,
    MediaMan5335

    Sad to say MediaMan5335, there's no real defined way to read
    a Flash movie file. Currently there are tips and tricks to do it,
    but all of them are merely patches to somethin long overdue and
    needed. Since Google is setting the trend, the best way to gain
    ranking is to follow their set of new rules.
    There were several ways to gain rankings, whether is be
    paying your way to the top, putting multiple links within your
    site, or placing tons of words that would be read by spiders.
    Google has multiple articles pertaining to Search Engine
    Optizmization or SEO. Head on over to Google and just type in
    "Google SEO" and you'll find a multitude of articles.
    Right now to answer your question, META KEYWORDS and META
    DESCRIPTION are your best tools for METAs. Having legit links
    INBOUND and OUTBOUND will help.
    Currently there a several companies working on allowing SWFs
    to be read by Search Engines. Hopefully this helps answer your
    question. SEO can be a daunting thing.

  • I need to know how to make a game !!!!!

    I am 12 years old and i need to know how to make a game... i'm very good with computers and i just need to know how to make a game.. like runescape.

    you should start with something little, first try do make a rectangle on screen, then try to make it move.
    if you're past that, then you're allmost there.
    of course, eventually during making a game like runescape you would need lot's of knowledge about data structures and matm and physics and whatever is also needed in order to cread 3D universe.
    but with little practice you get to be master.
    good luck.

  • Dose any one know how to make a game simular to runescape?

    what i am talking about is i want to make a agme for my website.
    i want it to be a mulity user game where charators can interact with another. So dose anyone have any videos i can whats like a tortorial to make one or any info.
    Thank you for ur help.

    I dont know how to make a game like runescape, but to be quite honest it was runescape that got me starting. In april last year I toke the Java tutorial with the aim to create an online multiplayer role playing game. When I was done with the tutorial I posted some messages i gamecreation forums around to try and find a designer to work with. Around august last year I found him and we had a conversation about how to do it. He told me about opengl, animation techniques and alot of other stuff that day. Stuff I didnt understod the first thing about. But he told me to read up on it since it was good stuff to know if you want to make a good game.
    I toke some tutorials at NeHe's openGL site. They are not the best I have seen but they taught me the basics. after that I did something cracy. I tried to find out how to make skeletal animation work so we could use my designers skeletal animated 3d models. I wrote a parser and 3 month later I understod and implemented skeletalanimation into the engine. Btw. I use something called JOGL to access OpenGL from Java. Next step was to implement tweening, kamera and thats where I am now.
    I toke a loan im my appartment to give me untill feb. 2007 to finish something and Im working everyday on this project. Good thing is that my designer is just as devouted and has also made arrangements so he doesnt have to work for a while. Now he can use all his time rigging, animating and making textures for characters, monsters, the world and so on.
    Its looking good so far and I havent lost my motivation and lust yet, but there is a long way to a finished game.
    I still have to learn about collision detection, culling, octrees, networking and a billion other issues but I enjoy leaning and working with it.
    When thats done there will be gameplay, AI, a balanced economy system and so on to develope.
    Its a long journey, but if all this dont hit you in the stomach and if you think you have the mental stamina for it, I would say go for it. If you succeed, good for you. If not, you gave it a shot!
    Good luck!

  • How to make an indicator takes more than one input

    Hello,
    I want to know how to make an indicator ( like gauge for example) response to more than one case strrcuture result. In other words, how the indicator can take more than one input and move based on different input values ( the arrow of the gauge moves to different angles basesed on the logic structure and not only to one degree).
    Thanks in advance,
     

    YES, you got it right Coastal !
    This is what i want to do,
    I dont know how to establish this output in the software, i am still learning LabVIEW.
    I put a merge block to join the outputs but it didnt work.
    check it in the attached VI file.
    I am sure it is an easy thing but I dont know how to implement it.
    Any help you provide is appreciated,
    Best wishes 

  • How to make a game menu..

    How do you go abouts on making a game menu???
    I Know how to make a button with gotoAndStop, and gotoAndplay. I understand timeline coding. And have started with classes and OOP, im ok at writing classes i guess.
    But I have know idea how to make a menu that has basic things like instructions start ect basic things.. I have a library with a exported SWC, so i presume i need to grab my graphical assets from this, correct? or is there other ways?

    Thank you for this i have stumbled upon this before.
    Now really the real question is how do i add my game to that? I have a Main class attached to my game currently.. With a FLA holding graphics (I know i can add my buttons to this fla.) Thats the problem my game is currently the documents class. So if i change it to the main provided by emmanuel. that communicates with the the_game_itself.as, but im unsure as to how im supposed to put my code in this and still communicate with the main document class?
    If you want to see my code, let me know.

  • How to make view automatically scroll when keyboard show up

    Hi all
    I'm like a totally noob for objective-c coding, let alone the iPhone programing. :P
    Anyway, I somehow manage to create a simple application that receive input via UITextField, do some simple math, then display the result in other UITextFields (which can act as a input vice versa).
    Problem is, when I use the UITextField at the buttom of the screen as an input, the keyboard will block that text field out of my view, so I could not see what I'm typing at all.
    That's the question. How to make my view scrollable, and make it simply scroll itself out of the way when the keyboard is shown? I already inherit my view from UIScrollView, but don't know what to do next. Can you guys help enlighten me, please?
    Thanx

    Of course, if you're dealing with textFields, you should change a few things try something like that in your .m file :
    - (void)textFieldDidBeginEditing:(UITextField *)theTextField
    if ([theTextField isEqual:yourTextField])
    // Restore the position of the main view if it was animated to make room for the keyboard.
    if (self.view.frame.origin.y >= 0)
    [self setViewMovedUp:YES];
    // Animate the entire view up or down, to prevent the keyboard from covering the author field.
    - (void)setViewMovedUp:(BOOL)movedUp
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    // Make changes to the view's frame inside the animation block. They will be animated instead
    // of taking place immediately.
    CGRect rect = self.view.frame;
    if (movedUp)
    // If moving up, not only decrease the origin but increase the height so the view
    // covers the entire screen behind the keyboard.
    rect.origin.y -= kOFFSETFORKEYBOARD;
    rect.size.height += kOFFSETFORKEYBOARD;
    else
    // If moving down, not only increase the origin but decrease the height.
    rect.origin.y += kOFFSETFORKEYBOARD;
    rect.size.height -= kOFFSETFORKEYBOARD;
    self.view.frame = rect;
    [UIView commitAnimations];
    - (void)keyboardWillShow:(NSNotification *)notif
    // The keyboard will be shown. If the user is editing the author, adjust the display so that the
    // author field will not be covered by the keyboard.
    if ([yourTextField isFirstResponder] && self.view.frame.origin.y >= 0)
    [self setViewMovedUp:YES];
    else if (![yourTextField isFirstResponder] && self.view.frame.origin.y < 0)
    [self setViewMovedUp:NO];
    #pragma mark - UIViewController delegate methods
    - (void)viewWillAppear:(BOOL)animated
    // watch the keyboard so we can adjust the user interface if necessary.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)
    name:UIKeyboardWillShowNotification object:self.view.window];
    - (void)viewWillDisappear:(BOOL)animated
    [self setEditing:NO animated:YES];
    // unregister for keyboard notifications while not visible.
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    be sure to invoke the method when you dismiss the keyboard, so that the view "falls back" to its normal state:
    if (self.view.frame.origin.y < 0)
    [self setViewMovedUp:NO];
    Of course, declare the method
    (void)setViewMovedUp:(BOOL)movedUp;
    in the .h file
    and the #define you will use in you .m file :
    // the amount of vertical shift upwards keep the text field in view as the keyboard appears
    #define kOFFSETFORKEYBOARD 50.0
    // the duration of the animation for the view shift
    #define kVerticalOffsetAnimationDuration 0.30
    good luck !

  • HOW TO MAKE THIS GAME MULTIPLAYER???

    its in java but i would like to know how to make it multiplayer so i can host a game for others over the internet
    http://www.nintendo8.com/game/321/tecmo_super_bowl/
    theres the link to the game

    KRhodes330 wrote:
    its in java but i would like to know how to make it multiplayer ...By leaning Java.

  • How to make finder side scroll?

    i did it once, but when i deleted the pref file( in a bad finder situation), so now i forgot how i made it to scroll side. Anyone, thanks in advance!

    I'm afraid I don't understand what you are talking about. Can you post a picture on a .me or flickr account and give us a URL to the image to point to us what you are talking about? Screen captures are done as described here:
    http://www.zimbio.com/MacOS+X+version+10.5+Leopard/articles/13/Mac+OS+X+screen+capturetips

  • Reading a graphic novel is very awkward with ADE.  Is there a way to make it scroll more smoothly?

    This is, by far, the worst client for graphic novels.  It's slow and jerky to the point of being distracting.

    you can disable smooth scrolling.
    *Tools > Options > Advanced > General: Browsing: "Use smooth scrolling"

  • How to make a game smooth

    Hi there,
    i am developing a game and have all but finished it. But there is a problem, when i want to play the
    game in a larger applet size it goes slower and flashes. i have set the priority level of the thread to 1.but it
    still does it. What am i missing?

    Priority 1?
    Thread.MAX_PRIORITY seems better.
    You'd still need double buffering to avoid flickers, though.
    + add two member variables:
    + insert two lines into yout init()-method
    + write an update()-method
    Image bgi;
    Graphics bgi_g;
    public void init(){
    bgi= createImage( 400,400);
    bgi_g= bgi.getGraphics();
    public void update( Graphics g){
    paint( bgi_g);
    g.drawImage( bgi, 0,0, this);
    }

  • How to make a text becoming more and more visible?

    Maybe I didn't use google well, but I didn't find anything in the internet what could solve my question.
    I basically want to work with a white background, where a text is on which becomes more and more visible the more it comes closer to the bottom. The tricky thing is, it's for a website, so it has to be responsive for smartphones or tablets for example (first idea: put the white background layer to the front like it makes the text behind it more and more visible/invisible?). Any ideas how to solve that? Would be so great to know.

    I'm not sure what it means to "be responsive for smartphones or tablets"...  People put complex graphics on those things all the time.  They have unprecedented power.
    Photoshop can help you do what you're describing.  What you want is no more complex than putting a gradient mask on a layer so as to create partial transparency.  You could have fading text (as a graphic) or a fading solid color fill that would overlay text rendered by a browser.
    Just some graphic ideas...
    Save as a PNG-24 to get partial transparency that a browser can render.
    -Noel

  • How to make a JDialog scrolling from one position to the other.

    Hi all,
    I want to move a JDialog from one position to the other(actually I want to scrolling/moving as messenger notification appear on top of the system tray) on the desktop.
    Anyone of you can give me a clue.
    Thanks

    Ok here what I have try up to now. First make the initial position of the JFrame as follows.
        private void SetWindowLocation()
            final int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
            final int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
            final int frameHeight = this.getHeight();
            final int frameWidth = this.getWidth();
            int _y = (screenHeight - frameHeight - 32);
            int _x = (screenWidth - frameWidth);
    // Initial location
            this.setLocation(_x, _y); 
    }This code place my Frame in the lower-right corner on top of the system-tray.
    Then as you guys says, try to work on a Timer. Now I'm stuck with the action listener. I try to move the frame to upper-right corner.
        private void SetWindowLocation()
            final int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
            final int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
            final int frameHeight = this.getHeight();
            final int frameWidth = this.getWidth();
            int _y = (screenHeight - frameHeight - 32);
            int _x = (screenWidth - frameWidth);
    // Initial location
            this.setLocation(_x, _y); 
            _timer = new javax.swing.Timer(100, incrementYPosition);
    ActionListener incrementYPosition = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                       while(_y > 0){
                            // do the processing here.
                            // reduce the _y value and set the new location with _x
                    };I'm stuck with that how to involve with the ActionListener here. :(:( After set the initial location how to deal with the ActionListener.
    Any help.

  • Dear experts.I want to know how to make XO game versuses undefeatab​le program using labview "extra free Kudos" for all.

    Dear masters in labview :I want to know how to add to XO game in labview a feature where a single player plays against  any programed program and never wins.
    Free Kudos for anyone who is able to solve this problem.
    Thank you for your time.
    Best regards,
    Jupiter
    extinct when hell froze over

    jcarmody wrote:
    I'd also like to join in the OP's offer of free kudos to anyone that can write a tic-tac-toe game that can consistently beat me.
    Now that's suddenly an entirely different requirement!
    "user never wins" != "program can beat user"
    Since the perfect game is a draw, "user never wins" is actually possible, but it can never beat a perfect player.
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for

  • There has to be a fix to this!

    Everytime that I try to play songs that I have purchased, it asks me to authorize my computer. I have many times and it still don't work. I have even deleted the sc folder contents and even that didn't work. I have de-authorized then re-authorized an

  • Property editor, Permission editor and security zone

    Could anyone let me know what different between <u>Property editor, Permission editor and security zone</u> when we build the new role in portal and have to go through these three for setting up. Could you compare them with creating new role in R/3 s

  • Migrating forms to 11g - problems with absolete built-ins

    Sorry if it's the wrong section, but nerves are kicking in and I'm lost. I've been trying to migrate an old, probably 8i database with its tools and forms into 11g. All software seems to run fine, but when I try to run the forms I either get "this fo

  • "Proper" way to export 5.1 surround tracks thru Compressor

    I did a quick search for this topic and couldn't find anything that really fit. I just finished a concert video (using 3 cameras and FCP's multiclips!) and was provided 6 tracks of AIFF audio (5.1 formatted) by the sound engineer. Everything syncs up

  • AirPlay Mirroring from 10.8 Won't Start Sending Video (or Audio)

    This question may have been answered, but searches for me keep coming up with people who don't have the AirPlay Mirroring icon showing up in the menu bar, which isn't the problem I'm having. In my case, the Mac is compatible (latest-gen Air, 10.8.5),