This site requires JavaScript, please enable it in your browser!
Greenfoot back
AreebRaza
AreebRaza wrote ...

2016/6/8

Enemy Health Not Working

1
2
AreebRaza AreebRaza

2016/6/8

#
and do i do the same with Skeleton2
danpost danpost

2016/6/8

#
AreebRaza wrote...
You mean like this: < Code Omitted >
No. Now switch lines 45 and 46.
AreebRaza wrote...
and do i do the same with Skeleton2
danpost wrote...
< Quote Omitted > Insert at line 45 of the Skeleton1 class (and the Skeleton2 class) the following:
return;
AreebRaza AreebRaza

2016/6/8

#
danpost wrote...
AreebRaza wrote...
You mean like this: < Code Omitted >
No. Now switch lines 45 and 46.
AreebRaza wrote...
and do i do the same with Skeleton2
danpost wrote...
< Quote Omitted > Insert at line 45 of the Skeleton1 class (and the Skeleton2 class) the following:
return;
ok it finally worked! but when i reset the game it goes through the skeleton
danpost danpost

2016/6/8

#
AreebRaza wrote...
ok it finally worked! but when i reset the game it goes through the skeleton
Remove 'static' from the 'health' declarations lines in the Skeleton classes at line 20.
AreebRaza AreebRaza

2016/6/11

#
thanks alot danpost but i have one last question is it possible to make enemies with health in one class
danpost danpost

2016/6/11

#
AreebRaza wrote...
is it possible to make enemies with health in one class
What are the differences between the classes?
danpost wrote...
Remove 'static' from the 'health' declarations lines in the Skeleton classes at line 20.
Actually, I do not think anything in those classes should be declared as 'static' (as yet), except for maybe the images. Remove all occurrences of the word 'static' in those classes. Note (do not make any changes for this unless you fully understand or get further help on this): I mentioned the images because currently, as your code is, each enemy will have its own set of images to use (even though the images are all exactly the same). By making the images 'static', only one set of images will be created for all enemies to use (this would be a great savings on memory usage as images require chunks of it). Also, they can be initialized when the project is compiled saving on CPU tasking during run-time. The fields can even be made as class constants using the 'final' keyword. Furthermore, all the images can be scaled appropriately during compilation, as well (if needed, you can ask for help on this). Placing the images in an array would also help for organizational purposes and making the code less bulky.
You need to login to post a reply.
1
2