Skip to main content
gamedev.net
🔒 Locked

[java] Few quick applet questions

Started by jetrii Dec 6, 2006 at 7:46 PM 7 replies 1k views
Original Post
jetrii
jetrii
I've been wanting to make a game for a while but I have a few questions: 1.) Should I use an applet? While a JFrame may give me more performance, it seems like I can reach more people with an applet. 2.) How would I go about rotating an image or shape? I tried affline transformation and BufferedImages but I am still confused...
SKATIN_HARD
SKATIN_HARD
I can give some insight on these questions. I would say use an applet if the game is a simple puzzle game. Performance wouldn't take much of a hit and you could easily put the game on a site somewhere. If the game you are making is going to be something more complex then you should use JFrame or whatnot.

As for question 2, I found this site here that might be of some help.

Good luck.
Jimfing
Jimfing
Why should having the game in an applet make any difference to performance?
Alrecenk
Alrecenk
It won't. The primary reason to use an application over and applet is that it is easier to save and load external stuff(save and load games or images or sounds). Applets have lots of permissions stuff that can be a pain to deal with sometimes.

The best way I know of to rotate an image is to use pixelgrabber and apply a matrix transformation to the pixels manually, and then use a databufferint to get them back onto a buffered image, but that can be somewhat involved(and a little slow) so I wouldn't recommend doing it alot. Also, it's a good idea to keep the oringinal image and always rotate from that because rotating tends to cause a loss in picture quality.
Luckless
Luckless
anything that gets above what you would call simple should be used as a Java Web Start or straight up application (I'm still somewhat fuzzy on the differences between something that is just an application, and what more/less a web start application has to offer to the user/programmer). Running things in the browser can get a little annoying, and you can be forced to jump through hoops to do things that are easier without it (Mainly things like saving files, and communicating with other servers and stuff. You step out of the more protected sandbox).

A rule of thumb I got from someone that had apparently been working with Java since it was released to the public: If you are making something for the web, look at your program and if you think that it would have been a hit on an 8bit console, go for applet, 16bit SNES, you might be looking for a little more elbow room, and above that go for an application.
Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.
falkone
falkone
I agree that you should go with a JFrame-based application. Web Start is a decent alternative to applets. If you really want to do an applet-based game, it should be fairly trivial to add the applet to the JFrame (like you would any other swing component). But, again, you're still limited by the applet end of the framework, assuming you want it to continue to work in both.
Disclaimer: "I am in no way qualified to present advice n any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)" o
capn_midnight
capn_midnight
I am of the opinion that Applets were a bad design decision from the very beginning, and today they are nothing but a buggy oddity. Yes, Applets actually have a number of bugs unique to themselves.

Java Web Start is a means for deploying Java Applications. You would still use JFrames to make your Web Start application. Web Start just manages the versioning of your application, making sure everyone has the latest version of your application.

Use the JFrames. Java Web Start solves the deployment issues that Applets were meant to solve without introducing new bugs to your application.

For rotating an image, it somewhat depends on what you want to do with that image. If you are just rotating it on the screen for rendering (i.e. you don't need to save the image like that afterwards) then you can call the rotate method of your java.awt.Graphics2D object.

You might be saying "But capn_midnight, I only have a java.awt.Graphics object". Fortunately for you, you're actually wrong. All painting methods in Java are actually passed a Graphics2D object. They are passed as references to Graphics objects for compatibility reasons. Just typecast your Graphics object to a Graphics2D object and you're good to go.

Example:
class MyFrame extends JFrame{    public void paint(Graphics gOld)    {        Graphics2D g = (Graphics2D) gOld;        g.rotate(myAngle);        g.drawImage(myImage, x, y, null);    }}
eedok
eedok
here's my code for when I rotate images:
//get the original tranformation stateAffineTransform old = g.getTransform();//Set where to draw the imageg.translate(x,y);//rotate the canvasg.rotate(-Math.atan2(mouse.x-x,mouse.y-y)+Math.toRadians(180));//draw the rotated image at the point relative to the transformation made above(will be rotated at 0,0)g.drawImage(sprite,-16,-16,null);//Orient the canvas the way it was beforeg.setTransform(old);

capn_midnight
capn_midnight
Quote:
Original post by eedok
here's my code for when I rotate images:
//get the original tranformation stateAffineTransform old = g.getTransform();//Set where to draw the imageg.translate(x,y);//rotate the canvasg.rotate(-Math.atan2(mouse.x-x,mouse.y-y)+Math.toRadians(180));//draw the rotated image at the point relative to the transformation made above(will be rotated at 0,0)g.drawImage(sprite,-16,-16,null);//Orient the canvas the way it was beforeg.setTransform(old);


well, atan2 takes the change in y value first, not the change in x value. Also, I would say it's conceptually innacurate to say that the transformations are orienting the "canvas". Calls to the transformation methods like translate, rotate, scale, etc., alter the transformation matrix, which is applied to individual *objects* as they are rendered.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.