Results 1 to 4 of 4
Thread: Projectiles
- 03-12-2012, 11:25 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
Projectiles
I'm trying to make projectiles(bullets)for a game I'm working on,but I still need to find out how to do a couple things.My projectiles don't appear,and I need a way to get rid of them,since there's no way to delete objects in java from what I've heard.I also need a way to stop everything from happening immediately,such as the sleep proc in my previous language.Thanks in advance!

Java Code:public void paint(Graphics g){ super.paint(g); if(shot == true) if(p.direction == 1); g.setColor(Color.BLACK); g.fillOval(tileX,tileY, 64, 64); //insert deletion code between these,to give the illusion projectile is moving g.fillOval(tileX+26, tileY, 64, 64); g.fillOval(tileX+51, tileY, 64, 64); g.fillOval(tileX+76, tileY, 64, 64); g.fillOval(tileX+101,tileY, 64, 64); if(p.direction == 2); g.setColor(Color.BLACK); g.fillOval(tileX,tileY, 64, 64); g.fillOval(tileX+26, tileY, 64, 64); g.fillOval(tileX+51, tileY, 64, 64); g.fillOval(tileX+76, tileY, 64, 64); g.fillOval(tileX+101,tileY, 25, 64); if(p.direction == 3); g.setColor(Color.BLACK); g.fillOval(tileX,tileY, 64, 64); g.fillOval(tileX+26, tileY, 64, 64); g.fillOval(tileX+51, tileY, 64, 64); g.fillOval(tileX+76, tileY, 64, 64); g.fillOval(tileX+101,tileY, 25, 64); if(p.direction == 4); g.setColor(Color.BLACK); g.fillOval(tileX,tileY, 64, 64); g.fillOval(tileX+26, tileY, 64, 64); g.fillOval(tileX+51, tileY, 64, 64); g.fillOval(tileX+76, tileY, 64, 64); g.fillOval(tileX+101,tileY, 25, 64); if(keycode == KeyEvent.VK_1){ shot = true; repaint(); }
-
Re: Projectiles
Use Thread.sleep(ms) to stop the thread for a number of millis.
You can delete objects in java. Just assign the object to null when its not needed and the garbage collector will remove it.
You should read a basic tutorial on game programming in Java, here is a link:
Java(TM) Boutique - The Java Game Development Tutorial - Page 3
- 03-13-2012, 12:59 AM #3
Re: Projectiles
You won't want to put a call to sleep in the paintComponent method.
The call to repaint() should be done outside of the paintComponent method
What do you mean by "get rid of projectiles"? Are you talking about something that is being drawn on the GUI?
Stop drawing them will make them disappear.
-
Re: Projectiles


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks