[ATTACH]3866[/ATTACH]
6 replies to this topic
#1
Posted 16 May 2011 - 08:32 AM
This is my first big project in Java, I've been with the help of advisors and artists so far, and now I'm coming to this forum for help. The game is in the form of an applet. When I tell it to run the applet in NetBeans, it doesn't run. It comes up with a gray box and sits there. My code is attached to this post in the form of a ZIP file containing the NetBeans project files, sources, etc.
[ATTACH]3866[/ATTACH]
[ATTACH]3866[/ATTACH]
|
|
|
#2
Posted 16 May 2011 - 01:40 PM
You have
So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);
Instead, as I think it's double buffering you're attempting there, add this line as last line:
If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.
update(g);as last line in the paint method. that update does this (ctrl-click it in netbeans):
public void update(Graphics g) {
if (isShowing()) {
if (! (peer instanceof LightweightPeer)) {
g.clearRect(0, 0, width, height);
}
paint(g);
}
}
So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);
Instead, as I think it's double buffering you're attempting there, add this line as last line:
g.drawImage(bg, 0, 0, null);
If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.
#3
Posted 16 May 2011 - 07:11 PM
wim DC said:
You have
So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);
Instead, as I think it's double buffering you're attempting there, add this line as last line:
If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.
update(g);as last line in the paint method. that update does this (ctrl-click it in netbeans):
public void update(Graphics g) {
if (isShowing()) {
if (! (peer instanceof LightweightPeer)) {
g.clearRect(0, 0, width, height);
}
paint(g);
}
}
So you have your paint method calling update, which calls paint() in there, which will again call update, paint, update, paint, ... stackoverflowerror.
Just remove that last line of update(g);
Instead, as I think it's double buffering you're attempting there, add this line as last line:
g.drawImage(bg, 0, 0, null);
If you read this before i'm awake again (going to bed now), the app can't find your images. Set your color to black and you'll see it gets painted.
(images are searched at tanks/build/classes/ but they aren't placed there upon compiling/running.
Manually copying them there works.
Thank you, that's fixed a first problem, but now another couple of problems come up. Now, for some odd reason, when it draws the tank moving, it doesn't erase the previous tank that it draws. Another issue is that when the game starts and the first shot is fired, the game crashes.
#4
Posted 16 May 2011 - 11:53 PM
Quote
Now, for some odd reason, when it draws the tank moving, it doesn't erase the previous tank that it draws.
You can just paint the tank higher so it's on the ground so it will be overdrawn aswell, also looks more normal. (paint it at y-position 436) Or else before you paint everything, paint a big white square over everything.
Quote
Another issue is that when the game starts and the first shot is fired, the game crashes.
for(int j = 0; [B][SIZE="5"]i[/SIZE][/B] < npc.length; j++){
#5
Posted 17 May 2011 - 05:47 AM
Well, that fixes those issues. Now, however, for some reason whenever anything happens, usually an object of the class EnemyBomb crosses the line of p1.xPos, it drops the lives to a negative number and the game is over. I'm not entirely sure why this happens.
[ATTACH]3867[/ATTACH]
Attached is the current code with all the changes I've made so far.
[ATTACH]3867[/ATTACH]
Attached is the current code with all the changes I've made so far.
Attached Files
Edited by ikoniq, 17 May 2011 - 07:11 AM.
#6
Posted 17 May 2011 - 07:57 AM
you if-statement in the 2nd for-loop from collisiondetection is wrong.
This is correct:
This is correct:
if(p1.xPos <= ebomb[i].xPos - ebomb[i].width && p1.xPos + p1.width >= ebomb[i].xPos && p1.yPos <= ebomb[i].yPos + ebomb[i].height && p1.yPos + p1.height >= ebomb[i].yPos)
#7
Posted 17 May 2011 - 08:10 AM
wim DC said:
you if-statement in the 2nd for-loop from collisiondetection is wrong.
This is correct:
This is correct:
if(p1.xPos <= ebomb[i].xPos - ebomb[i].width && p1.xPos + p1.width >= ebomb[i].xPos && p1.yPos <= ebomb[i].yPos + ebomb[i].height && p1.yPos + p1.height >= ebomb[i].yPos)
All right, that's good. Now then, all I'm waiting on (at the moment) is for the graphics to be done. If you notice any more bugs in the code, feel free to tell me, I've been looking for a place like this to have people openly check through my code as they please without having to worry about it getting stolen (I'm not sure why one would want to steal this...but I've seen stupider things being stolen.) Again, thank you for all your help.
Also, I'd like to make it a standalone application, if I could get some help with that. I've been working with applets, now I'd like to make it not browser-dependent.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account



Back to top









