How do you program sprites in JAVA ?

As far as I understand, a sprite is something you can move about without disturbing the background, because it is not paert of the frame buffer. But how do I write a code for it? Could someone please give me some hints?

to extend Malo's definition, a sprite is more commonly referred to as an "image that moves"-- not to be confused with animated images such as GIFs. the standard java library doesn't provide a Sprite object, but you can easily create one yourself...
public class Sprite {
     Image img;
     int x,y;
     public Sprite(Image img) {
          this(img,0,0);
     public Sprite(Image img,int x,int y) {
          this.img = img;
          this.x = x;
          this.y = y;
     public void move(int x,int y) {
          this.x+=x;
          this.y+=y;
     public void moveTo(int x,int y) {
          this.x = x;
          this.y = y;
     public void paint(Graphics g) {
          g.drawImage(img,x,y);
}something like that..

Similar Messages

  • How do you program Prefereces ?

    Hi,
    How do you program preferences ? Are there any examples of how to go about programming them ?
    Many thanks in advance.
    Aaron

    Cheers, I found that earlier, but I was wondering whether there was any thing that would work with a whole heirachy of objects and save there preferences and properties. Something a bit more advanced with a nice example :)
    Thank you for answering.
    I found this as well :-
    http://www.onjava.com/lpt/a/1272

  • How do you program a new number on iphone 4s?

    Hello,
    Ik live in Holland, but a friend off my mother has buy a iphone 4s in the US (America). He has used it by himself, and when he has buy it, his number was programmed in the iphone 4s. Now he has buy iphone 5, and he have give the iphone 4s to me. But you can't place a sim-card in it. So my question is : How can i program my phone number on the iphone 4s? I have try it by myself but it doesn't work ....

    If there is no SIM card slot available with the iPhone, it is not an iPhone 4S. It is an iPhone 4 that is a CDMA phone and can't be activated with any other CDMA network and can't be used with a GSM network either because it is not a GSM phone which includes/requires a SIM card slot.

  • Help!!! how do you program java!!!!!!!!!!!

    I am gettiing path problems where do I go.

    Nicely put Oliver. It's great to hear a non-newbie-bashing reply. It sets a good example.
    First, the best place to go is here.
    Though some people react strange when they are faced
    with what they call "stupid newbie questions", if you
    specify your problem detailed enough, you will always
    get help, at least by me :-)
    The best polace to look for documentation is SUNs JAVA
    tutorial which has proven to be very helpful for
    starters:
    http://java.sun.com/docs/books/tutorial/
    Feel free to ask questions and please take in account,
    that the more details of your problem are provided,
    the better help the better answers you will get.
    Oliver

  • How do you begin learning about Java?

    Hi. I'm new to Java. I began taking a class at the local Community college where I live. I'm in my second term. It's a lot harder than the first. I'm not sure if I still understand the basics. I've written in COBOL, RPG I,II,III&IV, C, C++, C#, Pascal, Fortran, and Basic...along with a few other languages, but I find Java the hardest one to understand and program in.
    Anyone out there got any advise as to how to begin?
    I still feel very lost.

    I am still learning myself. I have dabbled in programming since about 1976 when BASIC was available on the TRS-80 Model 1 but never did anything serious.
    Start with the Java Tutorials at http://java.sun.com/docs/books/tutorial then look at other tutorials. There are some here:
    <ul><li>Java Beginner Tutorial by
         Srini Appikatla</li>
    <ul><li>[http://www.javabeginner.com/]</li>
    </ul>
    </ul>
    <ul><li>Java Advanced Tutorials on
         ipodlot.com</li>
    <ul><li>[http://www.ipodlot.com/javalearner/test/advanced.htm]</li>
    </ul>
    </ul>
    I haven't worked through all of them but they look good so far.
    Next, buy some books. I like "The Java Tutorial" Forth Edition. Yes, it is the same as the web site but it is easy to read sequencially. It doesn't cost much, used on Amazon.
    Finally, actually write some code. It doesn't have to do much. Just play around. As you learn each new thing, try it out. It makes a big difference.

  • How do you create sprite reference in javascript format?

    I am a flash developer who is new to director. I am using
    java script syntax. I have done a bit of looking around with no
    luck, I assume I am missing something obvious.
    I declare a global array and try to add sprite references to
    it. Basically like I used to do in ActionScript in Flash.
    _global.fieldArrayFindAName_G = new Array();
    _global.fieldArrayFindAName_G[0] =
    _movie.sprite["_txtDonorField0"];
    trace(_movie.sprite["_txtDonorField0"]); // Message window
    shows <(sprite 6)>
    trace(_global.fieldArrayFindAName_G[0]); // Message window
    shows <(sprite 6)>
    // Crash here --> script error property not found #text
    _global.fieldArrayFindAName_G[varLoop].text = "";
    Any guidance would be greatly appreciated.
    TIA
    Tim

    I was missing something obvious.
    _global.fieldArrayFindAName_G[0] =
    _movie.sprite["_txtDonorField0"].member;
    And I need a seperate cast member with sprite for each text
    'field' I want to update. How clunky...

  • How do you access SENS in JAVA

    Hi, I would like to know how to access SENS (System Event Notification Service) in JAVA, any hints?

    You don't need the int declaration if it's already defined earlier in scope. If you're translating a large amount of code (not just this little piece), then that would appear to be the case (that i was already declared) as C also requires this, just as Java does.

  • How do you translate this in java?

    this is supposedly a c statement
    how is this translated in java?
    i mean, is this even possible?
    for (sum=0,i=0, j = 0; i < 10; i++, j+=2)
         sum += i+j;

    You don't need the int declaration if it's already defined earlier in scope. If you're translating a large amount of code (not just this little piece), then that would appear to be the case (that i was already declared) as C also requires this, just as Java does.

  • How do you underline type in java

    I am new to java and I can't seem to find a way to make type underline in a applet. do I add something to the g.string or is there a int. I need to use?

    Java does not support underlining as a font property. In order to do this properly, you need to look at the Java 2D text capabilities, esp. the TextLayout and related classes.
    Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

  • How do you install and run Java HTML converter 1.2?

    Hi,
    I just downloaded the Java plugin HTML converter (version 1.2) and after I unzipped the file, there was no exe file to run. Am I supposed to move all the files and directories somewhere else and run something at the command prompt?
    I wish they had better documentaion about this. I've searched all over java.sun.com and couldn't find a thing.
    Thanks all

    There is a new converter ver 1.3. Its written in Java so it needs the JRE to run. It comes with a BAT file to run it. It should be located here.
    C:\Program Files\HTML_Converter\converter\classes\HTMLConverter.bat
    The contents of the BAT file are the following:
    java -classpath %CLASSPATH%;. HTMLConverter %1 %2 %3 %4 %5 %6 %7 %8 %9
    I hope that helps.

  • Mighty Mouse: How do you program what buttons 3 and 4 do? NM

    intel imac   Mac OS X (10.4.9)  

    If you have a Mighty Mouse, use the pop-up menus to choose the action you want for each of the buttons. The scroll ball can also function as a button. To set a button to open an application, choose Other and select an application in the dialog that appears. Choose Button 3 (for the scroll-ball button) or Button 4 (for the side buttons) to use your mouse with a video game, CAD program, or other application that works with a multibutton mouse. Choose Off if you want a button to be inactive.

  • How do you program itunes to a new ipod?

    I just got a new ipod recently and had let someone else use my computer for itunes first! How do I get it so itunes will upload music onto my ipod without trouble! and also create new folders for stuff that i upload? (I have an 80gig classic)
    Thank you!

    You will have to be a lot more clear as to what EXACTLY is happening. As Chris already said, all you have to do is plug the iPod in and start using it. So if you are not getting stuff onto the iPod, then you are getting some sort of error?
    Patrick

  • The wireless keyboard doesn't have a page down key. How do you program a keyboard shortcut for Page Down?

    My new wireless keyboard doesn't have a page down key. Very customer-hostile, at least in Office Apps. The list of available keyboard shortcuts doesn't inclue Page Down. Anyone know how to program a keyboard shortcut for Page Down?

    Figured it out: fn + down arrow

  • How do you program the voicemail button on an iPhone 4s?

    I've seen lots of solutions using *5005*86 or whatever but this doesnt work for me. I have a UK registered phone provided but by my employer and uses Vodafone for voice and BTmobile for data. Is it this set up that is preventing me from programming the voicemail button?

    Voicemail is a carrier feature, not a phone feature, so your first step is to call Vodafone. Here's Apple's support steps:
    http://www.apple.com/support/iphone/assistant/voicemail/

  • How do you make links in Java?

    I want to make text that will link (hyperlinks) like in HTML, but none of my books cover this.
    Thanks.

    look in the middle of the page, theirs a little one i wrote.
    if you take out the graphics stuff.
    you have a few lines that, will let u make a link
    http://www.pietrick.com\jayspage\programingpages\appletpage.html

Maybe you are looking for

  • Slide Show Problems--Please help

    In Go Live CS 7.0.2, why does my slide show preview fine, but when I upload it to the internet it doesn't work? Please Help! Trouble page... http://www.ifsoinklined.com/Pages/traditional.html Thanks!

  • HT1657 Rented movie not working my ipad is saying "could not lode video"

    So I have a iPad mini and I rented a film and it wouldn't download it was saying download error and not working, so I went on to the videos app and tried to stream the film that worked for about 5 minuets after that a message just pops up saying "cou

  • Plugging in Ipod classic restarts computer + blue screen!

    So I haven't had a problem with my 80gb ipod classic until last night. Last night I updated my itunes and then plugged my ipod in to sync it. Within a second a blue screen had appeared on my computer and my computer restarted. I tried again today and

  • Sharepoint version number in document properties

    Hi, How can I set the SharePoint version number in my Word document, so that when the Sharepoint version number increases also the number in the document increases. We are running BPOS not 365. Thanks

  • Error in connecting to iCloud from Yosemite.

    I recently upgraded to OS 10.10.2. I cannot access accounts on Mail or iCloud settings in System Preferences. When asked to sign into my iCloud account in System Preferences with the correct password, the following messages appears:      "Account Det