http://i53.tinypic.com/waowhz_th.gif
im trying to make him run from one side of the screen to the other
this is the code
package miapplet2;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.net.*;
import java.awt.Color;
import java.awt.*;
import java.applet.*;
public class animacion extends Applet implements Runnable{
Image currentDoc;
Thread runner;
int xPos=10;
int ind = 0;
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
runner = null;
}
public void init() {
try{
URL u = new URL("http://i53.tinypic.com/waowhz_th.gif");
currentDoc = getImage(u);
} catch (MalformedURLException nameOfTheException)
{
System.exit(1);
}
}
void pause(int time){
try {
Thread.sleep(time);
} catch (InterruptedException e)
{
System.exit(1);
}
}
public void run() {
repaint();
}
public void paint (Graphics screen){
if (currentDoc != null) {
screen.drawImage(currentDoc, xPos, 10, this);
}
xPos += 10;
}
}
the problem is the character starts running from position 120, that is after all 12 frames have been drawn, i tried to use some double buffering but the problem persists, whats more the extra code adds some graphical bugs
all the examples ive seen so far of double buffering use 2DGraphics instead of imported images like this one so im not even sure if double buffering is the answer, in any case i need help with the double buffer code or any other viable alternative to solve this problem
edit: new code with the same problem
package miapplet2;
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.net.*;
import java.awt.Color;
import java.awt.*;
import java.applet.*;
public class animacion2 extends Applet implements Runnable{
Image DocPics[];
Image offscreenDoc;
Graphics offscreen;
Image currentDoc;
Thread runner;
int xPos=10;
int ind = 0;
public void start() {
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void stop() {
runner = null;
}
public void init() {
resize(700, 200);
try{
URL u[] = new URL[12];
u[0] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00000.png?t=1306805825");
u[1] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00001.png?t=1306806273");
u[2] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00002.png?t=1306805967");
u[3] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00003.png?t=1306805967");
u[4] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00004.png?t=1306805968");
u[5] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00005.png?t=1306806023");
u[6] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00006.png?t=1306806024");
u[7] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00007.png?t=1306806025");
u[8] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00008.png?t=1306806025");
u[9] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00009.png?t=1306806026");
u[10] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00010.png?t=1306806361");
u[11] = new URL("http://i1217.photobucket.com/albums/dd384/UnscrupulousUser/IMG00011.png?t=1306806362");
DocPics = new Image[u.length];
for(int i = 0; i<u.length ; i++){
DocPics[i] = getImage(u[i]);
}
currentDoc = DocPics[0];
} catch (MalformedURLException nameOfTheException)
{
System.exit(1);
}
offscreenDoc = createImage(size().width, size().height);
offscreen = offscreenDoc.getGraphics();
}
void DocRun(int veces){
if (currentDoc == DocPics[11])
currentDoc = DocPics[0];
else
if (currentDoc == DocPics[0])
currentDoc = DocPics[1];
else
if (currentDoc == DocPics[1])
currentDoc = DocPics[2];
else
if (currentDoc == DocPics[2])
currentDoc = DocPics[3];
else
if (currentDoc == DocPics[3])
currentDoc = DocPics[4];
else
if (currentDoc == DocPics[4])
currentDoc = DocPics[5];
else
if (currentDoc == DocPics[5])
currentDoc = DocPics[6];
else
if (currentDoc == DocPics[6])
currentDoc = DocPics[7];
else
if (currentDoc == DocPics[7])
currentDoc = DocPics[8];
else
if (currentDoc == DocPics[8])
currentDoc = DocPics[9];
else
if (currentDoc == DocPics[9])
currentDoc = DocPics[10];
else
if (currentDoc == DocPics[10])
currentDoc = DocPics[11];
else
if (currentDoc == DocPics[11])
currentDoc = DocPics[0];
repaint();
pause (100);
}
void pause(int time){
try {
Thread.sleep(time);
} catch (InterruptedException e)
{
System.exit(1);
}
}
public void run() {
Thread thisThread = Thread.currentThread();
while(runner == thisThread) {
DocRun(5);
xPos+=10;
}
}
public void update (Graphics screen){
offscreen.setColor(getBackground());
offscreen.fillRect(0,0,size().width, size().height);
offscreen.setColor(getForeground());
screen.setColor(getBackground());
screen.fillRect(0,0,size().width, size().height);
screen.setColor(getForeground());
paint(screen);
}
public void paint (Graphics screen){
if (currentDoc != null) {
offscreen.drawImage(currentDoc, 0, 10, this);
}
screen.drawImage(offscreenDoc, xPos, 0, this);
}
}
sorry for the trouble but i just cant figure out whats wrong with this
Edited by twinArmageddons, 31 May 2011 - 01:25 PM.


Sign In
Create Account


Back to top









