Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 9:13 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: how can time deplete?
PostPosted: Wed Sep 26, 2012 1:07 pm 
Offline

Joined: Sat Sep 08, 2012 4:03 pm
Posts: 74
I wanted when I destroy an object. It would show "Destroyed" then it will disappear. How can I make my text disappear?


Top
 Profile  
 
PostPosted: Wed Sep 26, 2012 1:15 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
One way to do it would be to keep a list of drawable text (including the text, their X,Y position, how long it stays, any code to make it move up or in a random direction, etc). Then during render time, you have a section that loops through these to draw the text. During update, you remove the ones that aren't valid anymore (ie: ran out of time, or some other stop condition).


Top
 Profile  
 
PostPosted: Wed Sep 26, 2012 2:08 pm 
Offline

Joined: Sat Sep 08, 2012 4:03 pm
Posts: 74
EXAPeLES?


Top
 Profile  
 
PostPosted: Wed Sep 26, 2012 2:19 pm 
Offline
Regular
User avatar

Joined: Mon Feb 07, 2011 8:48 pm
Posts: 182
Location: United Kingdom
Ugh... SystemNetworks do you have *any* experience in Java development?

_________________
Mirage Realms - A free, retro, 2D MMORPG being developed using Slick2D and TWL


Top
 Profile  
 
PostPosted: Wed Sep 26, 2012 2:19 pm 
Offline
Oldbie

Joined: Thu Mar 15, 2012 12:38 am
Posts: 260
Maybe this will work? I haven't compiled (and didn't test it). If I was a betting man, I'd say you'll have to fix a few things :)

Code:
public class DrawableText
{
   private String text;
   private int duration; //in MS
   private int x;
   private int y;

   private final static int Y_SHIFT = 1;


   public void render(Graphics g)
   {
      g.drawString(text, x, y);
   }

   public void update()
   {
      //Calculate time here - however you want
      duration -= 1000/60; //hopefully will decrement based on 60 FPS. You'll want to do this in a better way, obviously, but shows you the general idea of what I'm talking about here.

      y -= Y_SHIFT; //how much it moves "upwards"
   }

   public boolean isValid()
   {
      return duration > 0; //if 0 or under 0, then this is no longer valid and can be removed.
   }

}


Top
 Profile  
 
PostPosted: Sun Sep 30, 2012 8:07 pm 
Offline
Site Admin

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 140
dayrinni I appreciate your dedication to help SystemNetworks.

But feeding him code will not make him a better programmer, it will only result in more questions like:

Quote:
I wanted when I destroy an object. It would show "Destroyed" then it will disappear. How can I make my text disappear?


The reply
Quote:
EXAPeLES?
is stunning, he wants you to write the code for him?

SystemNetworks at least try before asking...
More topics like "please write code for me" will be deleted.


Top
 Profile  
 
PostPosted: Mon Oct 01, 2012 12:16 pm 
Offline

Joined: Sat Sep 08, 2012 4:03 pm
Posts: 74
Stef wrote:
dayrinni I appreciate your dedication to help SystemNetworks.

But feeding him code will not make him a better programmer, it will only result in more questions like:

Quote:
I wanted when I destroy an object. It would show "Destroyed" then it will disappear. How can I make my text disappear?


The reply
Quote:
EXAPeLES?
is stunning, he wants you to write the code for him?

SystemNetworks at least try before asking...
More topics like "please write code for me" will be deleted.

That is how I learn, I look through the examples and learn it even without comments. And 1 more thing, thats how I learned java too.


Top
 Profile  
 
PostPosted: Mon Oct 01, 2012 4:33 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
There are plenty of examples you can look through: (SlickVirium, SlickPuzzle, Scroller etc)
https://bitbucket.org/kevglass/slick/src/tip/trunk

It doesn't sound like you "learned Java" or how to program if you can't overcome these simple obstacles.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group