Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Strange Sprite Animation  (Read 1071 times)
0 Members and 1 Guest are viewing this topic.
Offline javamobilegame

Senior Newbie




Java games rock!


« Posted 2005-03-10 12:33:38 »

I use a random integer to determine which image will be
fallen (i.e: just like Tetris), so in the run method I apply:
public void run()
{
long st=0;
long et =0;
while(conti) {
st = System.currentTimeMillis();
y = y + 10;
repaint();
doDraw3(g);
randInt = Math.abs(rand.nextInt()%2);
System.out.println("name ID = "+nameID);
et = System.currentTimeMillis();
if ((et-st)<rate)
{
try { Thread.sleep(rate-(et-st));} catch (Exception exp) {}
}
}
}

For the paint method i.e doDraw3(g):
public void doDraw3(Graphics g) {
g.setColor(0x00000000);
g.fillRect(0, 0, 300, 300);


try {img00 = Image.createImage("/00.png");
      img01 = Image.createImage("/01.png");
}catch(Exception e) {}
if(randInt==0) {
nameID = "0";
s0=createNumber("/00.png");
               }
else if(randInt==1) {
nameID = "1";
s1=createNumber("/01.png");
}      
}
where s0 and s1 are sprites.
The result is the image is fallen from the top to the bottom, but the image is changing for every MillisSecond during the falling process.
I want to fix them. Do I have something is go wrong? Huh  Thanks for your reply!
Offline wooD

Senior Newbie




J2ME Developer


« Reply #1 - Posted 2005-03-10 19:54:36 »

You are changing randInt every tick and using that to choose which image to display.

You need to separate randInt from the current Y location and only change the randInt and the beginning of the process when the image reaches the bottom and starts again from the top.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
public void run()
{  
  long st=0;
  long et =0;  
  while(conti)
  {
  st = System.currentTimeMillis();

  if (y==bottom)
    {
    // the current falling image has reached the bottom
    // choose a new image and reset the image location
    // to the top
    randInt = Math.abs(rand.nextInt()%2);
    y = top;
    }
  else
    {
    y = y + 10;
    }
  repaint();
  doDraw3(g);
  System.out.println("name ID = "+nameID);
  et = System.currentTimeMillis();
  if ((et-st)<rate)
  {
  try { Thread.sleep(rate-(et-st));} catch (Exception exp) {}
  }
}

Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #2 - Posted 2005-03-11 15:11:47 »

Thanks for your reply, Mr Wood!
And my second question is does it necessary to add "doDraw3(g)" in the while loop?
since I already apply "y=y+10" and "repaint()" but when I remove the code of "doDraw3(g)", the "repaint" does not work anything for "y=y+10" for me (i.e the screen remains unchanged).
Thanks for your reply~
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wooD

Senior Newbie




J2ME Developer


« Reply #3 - Posted 2005-03-15 19:47:44 »

Looks like I missed that as well.

The doDraw3(g) should be in your paint method. If this is using the 3d apis, it may be different. I've not used them, so someone else will have to chime in.  If it's just a regular midlet, then put the doDraw3 in the paint method.

You may want to call serviceRepaints() after the repaint() method. This should (it has problems on some phones) wait at that point until the screen gets refreshed. I use it in all my games and have used wait()/notify() on phones that it doesn't work on.

Wood

Offline javamobilegame

Senior Newbie




Java games rock!


« Reply #4 - Posted 2005-03-17 15:10:08 »

I see. Thanks for your explaination~ Cheesy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (33 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (65 views)
2014-11-07 19:57:14

TehJavaDev (69 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (82 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!