I have no idea why the powerup class is not drawing by my paint Component?๐ญ
#I need help on my computer science final project
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
I uploaded your attachments as Gist. This makes them more accessible, for example to mobile users.
Can you please improve your question?
It's totally unclear what your problem is, i.e. what you expect to happen vs what actually happens, as well as a rough idea for where the error must be in the code, plus a short summary of what you have tried so far, so that we don't suggest you things to try that you've tried already.
Have you tried placing some breakpoints to follow your applicational flow?
the Power up class and the wall class is both extends from the map object class, they both are same but somehow only the wall class can be draw in the main game.
Also please remove unused code, and don't put multiple classes in the same file.
And can only be drawn is vague, do you mean it doesn't get rendered, do you get an error, etc..
ok, but why can't I put multiple classes in the same file?
it doesn't get rendered
Readability for one.
Is it because of the class name? Just for the record, I don't have any classes with the same name.
its hard to help, because you havent tried pinpointing where the problem could be, yet dumped an entire project here
not everyone has the time to dive into a project like that to help with a single issue
you gotta do a bit of debugging
cut down the amount of code helpers have to look through to help solve the issue
Ok, the problem is the uP from the main game can't be rendered by the paintComponent method in my Mario game. However, the wall class has exactly the same code and can be rendered by my game. Why is this happening?
if nothing is rendering for it, could be that onScreen is false
PowerUp doesnt override draw, so the implementation comes from MapObject
and the first check for that is java if(this.onScreen)
so im assuming its not rendering because onScreen is false
double check
I did but as I mentioned, the wall has exactly the same draw method and it works fine.
they are difference instances
so onScreen is probably true for the wall, but not for the powerup
even though they derive from the same class, they are different objects
(this is why understanding OOP is critical)
the class defines what an object and can do. but a single class can be used to create many objects
and all those objects have their own copy of the properties defined in the class, such as onScreen
so even though both come from MapObject, they each have their own onScreen flag. for the wall, its probably true. for the powerup, may be false
never tried this in code before, but try adding this before the checkjava if(this instanceof PowerUp) { System.out.println("PU: " + this.onScreen); }
then run your code
it is printing true but it is still not rendered by my game.
it is printing true but it is not rendered by my game.
is something being rendered over it?
sounds like it is being drawn, just not seen
its using the default implementation of MapObject. others use that same implementation
works for others, not for this. you already checked to see if onScreen is true, and it was
so the next question would be: is it being obscured by another render?
no it isn't