[java] some java questions
Over the last week I''ve been learning java and have had a lot of fun with it. I made a dozen basic games so far and have come up with a few questions I was hoping I could get help with..
First, is there a way to handle two different keys that are held down simataneously.. Such as when scrolling and shooting at the same time.
Second, is there a way to tell which mouse button was clicked when you get a mousedown message.
Also, is there anyway to do something like enum Gamestates in c++...
And finally, I can never seem to load images inside of classes, it will ever only work when loaded in the main class.?
Anyways, Thank you very much to anyone that can help with any of these,
-lao
First, is there a way to handle two different keys that are held down simataneously.. Such as when scrolling and shooting at the same time.
You just have to maintain a set of variables representing which keys are up and which are down. Whenever you receive a key event you can just modify the appropriate variable.
Second, is there a way to tell which mouse button was clicked when you get a mousedown message.
You can get it''s modifiers, and check which flags are set.
Also, is there anyway to do something like enum Gamestates in c++...
Look at www.ddj.com they have an article there about using putting enums into java. (ie simulating them).
And finally, I can never seem to load images inside of classes, it will ever only work when loaded in the main class.?
Strange. How are you loading the images?
Thank you very much, the info helped alot.
About the images, inside classes I load them like...
Image picture;
picture = getImage(getCodeBase(), "Fighter.bmp");
Thank you,
-lao
About the images, inside classes I load them like...
Image picture;
picture = getImage(getCodeBase(), "Fighter.bmp");
Thank you,
-lao
Image picture;
picture = getImage(getCodeBase(), "Fighter.bmp");
That is the correct way to load images, but java does not support bmp''s. Use a gif or a jpeg, or if you have a new version of the jdk a png (though that won''t work in a browser).
cheers,
John
picture = getImage(getCodeBase(), "Fighter.bmp");
That is the correct way to load images, but java does not support bmp''s. Use a gif or a jpeg, or if you have a new version of the jdk a png (though that won''t work in a browser).
cheers,
John
I have been having a similar problem with loading images in different classes other than my applet class. It appears that getImage() breaks the sandbox security if you use it from the util class.
Otherwise, getImage() is part of the applet class and will load fine from the applet.
I''m not really sure what the solution is yet, but I think you need to look into loading the image with another class such as getURL or something like that.
The best place to post for this would be on the Java2D forums on Sun''s site. Or even in the Java2D listserv. Both of them are great sources for online help.
borngamer
Otherwise, getImage() is part of the applet class and will load fine from the applet.
I''m not really sure what the solution is yet, but I think you need to look into loading the image with another class such as getURL or something like that.
The best place to post for this would be on the Java2D forums on Sun''s site. Or even in the Java2D listserv. Both of them are great sources for online help.
borngamer
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement