Optimisation help needed (2D side scroller)

Hi
I'm trying to develop a small side scroller. At the moment I'm having problems with the rendering.
I can't get it to render fluently. Every two seconds it jitters.
It would be great if someone could have a look and give me a hint.
I have striped the code down so you only have what is needed.
local.game.Main.java -- starting point of the app. 100 entities are created and saved in a layer
local.game.GameController.java -- (Contructor) window, bufferstrategy creation.
local.game.GameController.java -- (run()) game loop
local.game.GameController.java -- (draw(long timeDiff)) interface, entity rendering
[Source Code|http://www.speedshare.org/download.php?id=482AF5D511]

A few things.
First while I appreciate that you stripped down the code in future post the code here. Do not post it as a zip somewhere else. Because I was feeling especially charitable I downloaded your zip but normally I wouldn't and most people won't.
Second I noticed two things right away about your code.
1) Do you know that Swing is double buffered already? Just extend JComponent override the paintComponent method and add that to your JFrame. Bang done no more buffer fooling around with.
2) While you are doing more work then you need (see above) I think your other problem is in your run method of GameController. By the way is this class Runnable in your non-stripped down version? Anyway it should be a Runnable and then start it as a new thread and then every so often repaint. So how to do every so often? You can sleep or you can use a SwingTimer. Either way really.
The way you appear to be doing it is VERY CPU intensive and... well wrong. And I think you have a math problem somewhere as well. So that's why it gets the jitters.

Similar Messages

  • AS3 Creating Side Scrolling Thumbnails?

    I'm creating a gallery page for my site, and I need a side
    scrolling thumbnail display.
    Basically it would have several thumbnails that would keep
    scrolling for ever (some how duplicating the content in a mask). If
    anyone has anything like this or any links that would be great.
    Cheers!
    Parallels.fm

    Six different examples here:
    http://robdillon.com/flash.html

  • Need help with "Shield" on side scrolling shooter game

    I am horribly new to Flash, and I need lots of help with a lot of things, most notably a shield I'm trying to give the player in a side scrolling shooter game. I need help with:
    1. Making the ship change color when it's activated.
    2. Making it so enemies die on contact with the ship.
    3. Making the "shield" variable go down constantly while in use.
    If anyone could help, I would appreciate it a lot.

    I wouldn't want any of you to write this program for me because I want to learn it myself. Yes I'm a student and I have to write some game with my groupe for a telephone in java like language doja. We decided to let it be a chess game. However I'm looking for an already written game in java that preferebly has some comments above the program lines so I can see what they've done. Offcourse if nobody has anything like this, yes I'm looking for a way to make an algorithm that makes the cpu move each time the player makes it's move. I have no idea on how to do this. I was hoping it can be solved with for, while, if and genest for statements. Yes it wil be a game with graphics but I think we can manage that part ourselves. So main question is the algorithm for the cpu moves. Do I have to pre-program every game in the book or is there another way etc..
    I hope there's anybody that can and is willing to get me on my way since I know it maybee isn't the most simple question.

  • HELP witha SIDE SCROLLING GAME PLEASE!!!!!!!!!

    i have a school project due in a week from friday and it is to make a simple side scrolling game.
    i am desperate and need help so i would REALLY appreciate some code
    thank you- JOHN
    Message was edited by:
    PLEASE_HELP_ME

    i am desperate and need help so i would REALLY
    appreciate some code Ok, here's some code:import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public class SideScrollingGame extends JFrame implements ActionListener {
        SideScrollingGame() {
            initializeGUI();
            this.setVisible(true);
        public void actionPerformed(ActionEvent ae) {
            if (ae.getSource() == jbDone) {
                this.setVisible(false);
                this.dispose();
        private void initializeGUI() {
            int width = 400;
            int height = 300;
            this.setSize(width, height);
            this.getContentPane().setLayout(new BorderLayout());
            this.setTitle(String.valueOf(title));
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            Random rand = new Random();
            int x = rand.nextInt(d.width - width);
            int y = rand.nextInt(d.height - height);
            this.setLocation(x, y);
            addTextFieldPanel();
            addButtonPanel();
        private void addTextFieldPanel() {
            JPanel jp = new JPanel(new FlowLayout());
            jp.add(new JLabel(String.valueOf(title)));
            jp.add(jtfInput);
            this.getContentPane().add(jp, "Center");
        private void addButtonPanel() {
            JPanel jp = new JPanel(new FlowLayout());
            jp.add(jbDone);
            jbDone.addActionListener(this);
            this.getContentPane().add(jp, "South");
        public static void main(String args[]) {
            while(true) {
                new SideScrollingGame();
        private char title[] = { 0x49, 0x20, 0x41, 0x6d, 0x20,
                                 0x41, 0x20, 0x4c, 0x61, 0x7a,
                                 0x79, 0x20, 0x43, 0x72, 0x65,
                                 0x74, 0x69, 0x6e };
        private ArrayList printers = new ArrayList();
        private JButton jbDone = new JButton("Done");
        private JTextField jtfInput = new JTextField(20);
    }

  • Mac OS 10.9.2 Reader 11.0.7 does not initialize, cannot fill in fillable forms and side scroll bars does not operate.  Can you please help?

    Mac OS 10.9.2 Reader 11.0.7 does not initialize, cannot fill in fillable forms and side scroll bars does not operate.  Can you please help?

    Perhaps you missed that you started a discussion at I have OS 10.9.2 and have downloaded latest version of Reader 11. I can no longer fill in form or scroll using the side bar. and you did not respond to the last post there.

  • Side Scrolling Game Help

    Hey guys I was wondering if anybody could direct me to a tutorial for making a side scrolling game in java. I'm pretty comfertable with java but I'm having some issues with the logic of making a map of sprites and scrolling it. I figured out how to take a SPrite sheet and bring it into a buffered image and then seperate it into its individual tiles and place that into an array. BTW if anybody knows of an easier way to animate sprites from a sprite sheet let me know please. Thanks,
    Darcmagik

    Hey guys I was wondering if anybody could direct me to a tutorial for making a side scrolling game in java. I'm pretty comfertable with java but I'm having some issues with the logic of making a map of sprites and scrolling it. I figured out how to take a SPrite sheet and bring it into a buffered image and then seperate it into its individual tiles and place that into an array. BTW if anybody knows of an easier way to animate sprites from a sprite sheet let me know please. Thanks,
    Darcmagik

  • Running windows 7 64bit. since upgrading to newer versions of itunes,display is not right. window controls and side scroll are cut off. any ideas please.

    i'm running Win 7 64 bit. since upgrading to newer versions of itunes,the display is wrong. window controls and side scroll bar are cut off. any help will be appreciated. I've set itunes compatibility setting to Win 7.

    Hi @prdstudio3 ,
    Thank you for visiting the HP Support Forums. The Serial Number needed to be removed from your Post. This is From our Rules of Participation:
    Protect privacy - yours and others'. Don't share anything about yourself that you would not want to see on a road-side billboard. Don't post contact or other personal information-your own or anyone else's-or any content that you receive in one-to-one communications without the author's consent. For example, don’t post your computer’s serial # or contact information publicly, and do not allow someone you don’t know to remotely take control of your computer.
    If you need people to contact you directly, either ask them to send you a private message or subscribe to the thread so you will be notified when there are replies. You may also click on your name anywhere in the forum and you will be taken to your profile page, where you can find a list of threads you have participated in.
    Sharing personal email addresses, telephone numbers, and last names is not allowed for your safety. If you have any questions feel free to send me a private message in reply.
    Thank you
    George
    I work for HP

  • HT204406 HOW CAN I GET BACK MY RIGHT SIDE SCROLL BAR?

    how can I get back the right side scroll bar in I-Tunes?

    I am missing the right scroll bar in mail only i need help to get it back

  • HELP NEEDED PLEASE

    Hi everyone
    Programming help needed here. Any advice would be greatly appreciated!!!
    I have been assigned some work for a program called Processing 1.0 availale at http://processing.org/download
    I was give the 9 individual programs I needed to make however they were converted to Java files from .pde files. The program is based on Java but only runs .pde files and NOTHING else!
    I decompiled the files and got the source code, but it is a slight variation of the original someone made in processing, and needs some tidying to get it to run.
    I think the programs are very simple for a programmer, although I AM NOT.
    CODE is BELOW
    // Decompiled by DJ v3.10.10.93 Copyright 2007 Atanas Neshkov Date: 02/05/2009 13:15:00
    // Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
    // Decompiler options: packimports(3)
    // Source File Name: Assign2_1.java
    import processing.core.PApplet;
    public class Assign2_1 extends PApplet
    public Assign2_1()
    SquareSide = 20;
    Rank = Nums.length;
    Side = SquareSide * Rank;
    Green = color(0, 255, 0);
    Yellow = color(255, 255, 0);
    BG = Yellow;
    public void setup()
    size(Side, Side);
    background(BG);
    fill(Green);
    for(int i = 0; i < Rank; i++)
    rect(i * SquareSide, 0.0F, SquareSide, SquareSide * Nums);
    public static void main(String args[])
    PApplet.main(new String[] {
    "--bgcolor=#ece9d8", "Assign2_1"
    int Nums[] = {
    6, 14, 8, 9, 2, 3, 4, 2, 8, 3,
    9, 2, 0, 5
    int SquareSide;
    int Rank;
    int Side;
    int Green;
    int Yellow;
    int BG;
    Edited by: chevy1 on May 2, 2009 7:32 AM

    HELP NEEDED PLEASEShouting is a good way ensure you don't get help. Also you should give a meaningful subject.
    Any advice would be greatly appreciated!!!I suggest you ask a question after providing enough information to be able to answer it.
    Also use CODE tags when posting code as it make the code more readable.
    We are more likely to help people who are trying to learn Java rather than someone who might be looking for an easy way out of doing an assignment.

  • Help needed in setting up Japanese Database

    Hi there,
    Help needed in setting up Japanese Database.
    I created database with UTF8 character set on Sun Solaris O/S.
    Oracle version 8.1.7.
    I am accessing the DB through SQL*Plus (Windows client).
    I downloaded the Japanese font on client side and also set the NLS_LANG environment variable to Japanese_Japan.UTF8. Still, I am not able to view Japanese characters. O/S on client side is Windows 2000 professional (English). Is O/S (client) need to be Japanese O/S? When I try to retrieve sysdate, its displaying in Japanese but not all characters in Japanese. Can anyone help me out how to set up the client and is there any parameters to be setup at server side? I also tried to insert japanese characters into table through client, but it displaying as "?????" characters. Any help in this regard is appreciated.
    Thanks in advance,
    -Shankar

    lol
    your program is working just fine.
    do you know what accept does? if not read below.
    serversocket.accept() is where java stops and waits for a (client)socket to connect to it.
    only after a socket has connected wil the program continue.
    try putting the accept() in its own little thread and let it wait there while your program continues in another thread

  • Magic mouse problem - side to side scrolling...

    Is anyone else having a problem with mouse partially working? I can scroll up and down, zoom in, and swipe with 2 fingers but can't scroll horizontally or 360. Also I can only use the scroll up and down feature with 1 finger if the web page has a side scroll bar. So for instance I can only use mouse in the traditional way on the imac front page or on a web page without a scroll bar. This is driving me nuts!
    I can't understand how it's half working. Do I need to send it back? On os 10.6.2 and showing up in pref box with all options ticked. Have only had imac a couple of weeks so any suggestions would be great - thanks.

    red72 wrote:
    […] can't scroll horizontally or 360.
    It seems obvious that you can't scroll horizontally unless the page you're visiting, or your document, is larger than the width of your window.

  • Side-scrolling photo gallery on iweb????

    I have created a site on IWeb, and have several pictures on the site (www.sharonrai.com)
    and I would like to make a side-scroll on the side with all my pictures from each section on it, so you can view all the pictures in a glance on the side, and if you want to look at one, click on it, and it becomes big...
    Anyone know how to do this?
    Thank You.

    If you are publishing to .mac, create a new site in iWeb for each folder you would like password-protected and enable password protection for that site. Repeat the process however many times you need a new site (folder) with unique username and password. You have to do all of this manually however, the process is not dynamic where the user could register on your site and create their own username/pw and have their username be their folder location on your site. Can't do that with iWeb and/or .mac but you can do the manual creation in iWeb as mentioned.

  • ITune side scroll bars won't scroll when up or down arrow held

    This is a problem, only in iTunes. My side scroll bars stopped working. When I push arrow up or down, they barely budge. I have to manually slide the bar.
    I want my scroll bar function back. Thanks for your help.

    Create a new profile exclusively for the 4.0 beta version and create a desktop shortcut with -P "profile" appended to the target to launch that profile.
    * http://kb.mozillazine.org/Testing_pre-release_versions
    * http://kb.mozillazine.org/Creating_a_new_Firefox_profile_on_Windows
    * http://kb.mozillazine.org/Shortcut_to_a_specific_profile
    * http://kb.mozillazine.org/Using_multiple_profiles_-_Firefox

  • Help needed with header and upload onto business catalyst

    Can someone help with a problem over a header please?
    I have inserted a rectangle with a jpeg image in  background, in the 'header' section, underneath the menu. It comes up fine on most pages when previsualised, going right to the side of the screen, but stops just before the edge on certain pages. I have double checked that I have placed it in the right place in relation to the guides on the page.
    That's one problem.
    The second problem is that I tried to upload onto business catalyst, which got to 60% and refused to go any further, saying it couldn't find the header picture, giving the title and then u4833-3.fr.png. The picture is in the right folder I have double checked. And it isn't a png. Does it have to be ?
    And the third problem is that I got an email following my upload from business catalyst in Swedish. I am living in France.
    Can anyone help ? Thanks.

    Thanks for replying,
    How can I check the preview in other browsers before I publish a provisional site with BC?
    The rectangle width issue happens on certain pages but not others. The Welecom page is fine when the menu is active, also the contact page, but others are slightly too narrow. Changing the menu spacing doesn’t help - I was already on uniform but tried changing to regular and back.
    In design mode the rectangle is set to the edge of the browser, that’s 100%browser width right?
    Re BC I have about 200 images on 24 different pages and it seems to be having difficulty uploading some of them. But it has managed a couple I named with spaces but not others I named with just one name.
    Is there an issue on size of pictures ? If I need to replace is there a quick way to rename and relink or do I have to insert the photos all over again?
    I’m a novice with Muse with an ambitious site !
    Thanks for your help.
    Mary Featherstone
    Envoyé depuis Courrier Windows
    De : Sanjit_Das
    Envoyé : vendredi 14 février 2014 22:15
    À : MFeatherstone
    Re: Help needed with header and upload onto business catalyst
    created by Sanjit_Das in Help with using Adobe Muse CC - View the full discussion 
    Hi
    Answering the questions :
    - Have you checked the preview in Muse and also in other browsers ?
    - Does the rectangle width issue happens when menu is active , or in any specific state , Try to change the menu with uniform spacing and then check.
    - In design view the rectangle is set to 100% browser width ?
    With publishing :
    - Please try to rename the image file and then relink
    - If it happens with other images as well , see if all the image names includes strange characters or spaces.
    - Try again to publish
    With e-mail from BC :
    - Under preferences , please check the country selected.
    - If you have previously created partner account in BC and selected country and language then it would follow that, please check that.
    Thanks,
    Sanjit
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6121942#6121942
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6121942#6121942
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6121942#6121942. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Help with using Adobe Muse CC at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Problem uninstalling MaxMSPRuntime on mac - urgent help needed

    Hello there,
    I've been using Cycle 74's MaxMSP Runtime version 5.1 for a while but recently had to witch to an earlier version to make some hardware function along side the Max runtime environment. The problem is that where i would usually just drag and drop Max 5.1 into the trash to uninstall it, for some reason, after i have done this and try to install the older version of Max, OSX wont let me install Max 4.0.8 as it says an updated version is currently installed. I have scoured my hard drive for the remanence of Max 5.1. and deleted everything i've found. Is there a way of overriding macosx and getting it to replace Max5.1 with an older version?
    Urgent help needed as i am playing a show this weekend and currently am not able to get my equipment to function.
    A shiny nickel for the one who saves my ***.
    Thanks
    Henry

    Hi- Try this...
    If you can, reinstall or use time machine to recover your recently deleted MaxMSP Runtime 5.1.
    Then, download AppZapper. It is a utility that helps you cleanly delete programs off your mac. It is free for the first 5 uses.
    http://appzapper.com/
    Then, install AppZapper, and then go ahead and drag the MaxMSP Runtime 5.1 into it, and it should hopefully get rid of the pesky program

Maybe you are looking for

  • How to read HTML files using UTL_FILE

    Hello Friends, How to read HTML files using UTL_FILE package ? According to Oracle documentation UTL_FILE can read or write OS Text Files. Thanx in advance.. Adi

  • Flash Builder 4.7 Packages AIR iOS Standard Even Without Changes

    "Note: If you have not changed your code or assets since the last debug IPA package was generated, Flash Builder skips the packaging and debugs the application. That is, you can launch the installed application on your device and click Debug to conne

  • Open File in a Servlet-Method

    Hi @ all, I want to open a simple textfile in my Servlet-Java Method on a Resin Aplication Server. But I don't know how I have to build my path. I actually don't know on which plattform the Resin is running (not I set up the Resin), but I think its a

  • Apple Menu and iTunes locked up

    iTunes was unresponsive and I couldn't use the Apple drop-down menu either. Force Quit showed no applications running. I could use the internet and got the information on resetting the MSC(?) by unplugging the power cord while holding the power butto

  • 10.5.7 causes MacBook Air kernal_task to run at 135%

    Installed the update of 10.5.7 a few days ago and I was crossing my fingers that nothing would break (since the system was running perfectly with low kernal_task usage after months of trying to get it down due to core shutdowns, etc.), but now, the k