Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 1021 times)
0 Members and 1 Guest are viewing this topic.
Offline javamobilegame

Senior Newbie




Java games rock!


« Posted 2005-03-10 13: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 20: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 16: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 20: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 16: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.

E.R. Fleming (9 views)
2014-07-29 03:07:13

E.R. Fleming (4 views)
2014-07-29 03:06:25

pw (38 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!