Game Maker's Garage Forum

Game Creation => Other Languages & Tools => Topic started by: Gan on February 08, 2009, 09:43:54 AM

Title: Java Applets
Post by: Gan on February 08, 2009, 09:43:54 AM
Hey, I think I've figured out what language suits me best. Java.

I'm now learning how to program Java applets in Netbeans and it's way cool. Extremely easy too.


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on February 08, 2009, 10:12:02 AM
I have officially given up hope that you will ever finish your MMO.

That aside, I'm taking java classes at school and I really like the language.
Title: Re: Java Applets
Post by: Gan on February 08, 2009, 09:21:03 PM
I'm really feeling good about this. Also, I believe I will get through Avisaria with this. I've been playing around with it a lot and have been learning much.

For anyone who is interested, here is my Java progress page:
http://web.mac.com/avisaria/ProjectPage/index.html

I'll make it look better eventually.


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on February 08, 2009, 10:00:47 PM
The bad part of taking a class on java is that we're moving really slowly... my teacher said that we'll do games eventually.
Title: Re: Java Applets
Post by: Gnome on February 08, 2009, 10:03:19 PM
Stick with a language gan. PLEASE
Title: Re: Java Applets
Post by: Gan on February 09, 2009, 07:24:05 AM
I can't, there are still more mountains to climb.

My language list(Languages I have overcome):
 - SilverCreator basic
 - GameMaker(Know enough to make some stuff)
 - TntBasic
 - Vb6
 - Vb.net
 - Html
 - CSS

Once I learn a language, I move on.

Languages/Framework I have yet to learn:
 - Java (Already started)
 - JavaScript
 - Php
 - C++/Xcode Obj-C
 - iPhone SDK

Eventually if there are any other languages that seem interesting, I will add them to my mental list. Once I know everything I want to know, I will settle myself and take random jobs in different languages. I will also do varieties of projects. I just hope I can finish Avisaria before I move on again. If not I will start on making Avisaria in that new language.


-Gandolf
P.S. Does anyone have any trouble viewing any java applets on my Java page?
Title: Re: Java Applets
Post by: WarHampster on February 09, 2009, 10:14:00 AM
Your logic is fundamentally flawed... if you try to learn every language, you will never get anything done. Focus on one language and completely master it, and then make your game with that. I'm sure that you haven't mastered any of the languages on that list (except maybe silvercreator).

BTW iphone SDK isn't a language :P
Title: Re: Java Applets
Post by: Silverwind on February 09, 2009, 02:00:23 PM
Assuming Gan's enjoying what he's doing, his logic isn't flawed. ;)
Title: Re: Java Applets
Post by: Gan on February 09, 2009, 02:52:28 PM
I'm having much fun. My main goal is to learn many things about programming before college. Once in college I will focus more on creating fantastic things. Right now my goal is just to learn.


-Gandolf
Title: Re: Java Applets
Post by: Gan on February 09, 2009, 04:42:10 PM
Hey guys, updated my Java page a little bit.

http://web.mac.com/avisaria/ProjectPage/index.html


-Gandolf
P.S. Nobody has ever mastered a language, they have only learned as much as they want to or as much as they can. I'm only learning as much as I need to, than I move on.
Title: Re: Java Applets
Post by: Gan on February 12, 2009, 08:35:38 PM
Added another project onto my project page. So far so good.  ;)
http://web.mac.com/avisaria/ProjectPage/index.html


-Gandolf
Title: Re: Java Applets
Post by: Gnome on February 12, 2009, 08:52:47 PM
all i get is an error page

Title: Re: Java Applets
Post by: Gan on February 13, 2009, 07:14:51 AM
Sorry, didn't upload properly, try now.


-Gandolf
Title: Re: Java Applets
Post by: GMG Tim on February 13, 2009, 12:42:28 PM
Personally I've tried like 30 languages, and of those 30 I've found the right ones to use for certain situations-- Python for almost everything, PHP for web development, BlitzMAX for games, and C/C++ for optimized, fast code.

Ghost
Title: Re: Java Applets
Post by: Gan on February 13, 2009, 03:05:09 PM
I like Java, it seems to be very fast(just about C++ fast) and can be run on just about any platform. Though after Java I will further my learning of C++/Obj-C.


-Gandolf
Title: Re: Java Applets
Post by: GMG Tim on February 13, 2009, 07:18:51 PM
Quote
I like Java, it seems to be very fast(just about C++ fast) and can be run on just about any platform. Though after Java I will further my learning of C++/Obj-C.


-Gandolf

Java is like molasses compared to C/C++. You can't even begin to compare the two unless you're looking at them purely from a syntactical standpoint. C/C++ is the fastest you can get without coding in assembly.

Ghost
Title: Re: Java Applets
Post by: Tireas Dragon on February 13, 2009, 07:50:00 PM
Binary is the Fastest however it is useless for making games
Title: Re: Java Applets
Post by: Gan on February 13, 2009, 08:44:02 PM
Quote
Conclusions: Why is "Java is Slow" so Popular?

Java is now nearly equal to (or faster than) C++ on low-level and numeric benchmarks. This should not be surprising: Java is a compiled language (albeit JIT compiled).
Nevertheless, the idea that "java is slow" is widely believed. Why this is so is perhaps the most interesting aspect of this article.

http://www.idiom.com/~zilla/Computer/javaCbenchmark.html

For the complete conclusion, refer to the bottom of the page.


-Gandolf
Here is a neat benchmark graph that'll clear a few misconceptions up:
http://reverseblade.blogspot.com/2009/02/c-versus-c-versus-java-performance.html
Title: Re: Java Applets
Post by: GMG Tim on February 13, 2009, 09:34:36 PM
Okay, first off, I have no clue who authored that blog you mentioned (nor do I know how he conducted his benchmark). However, the other paper you mentioned has been the subject of controversy-- even I had some doubts about it.

Bottom line-- there have been doubts raised about the author's methodology among other things. The general consensus is that Java is getting faster, but C++ still out performs it on arithmetic/trigonometric operations, while Java outperforms C++ on I/O operations.

I was surprised by the article you gave me, because during my 3 years at one of the largest research institutions in the world, I've never heard any of my professors advocate that Java was faster than C++. Java is getting faster, but C++ is still a winner overall.

http://www.freewebs.com/godaves/javabench_revisited/
http://www.ddj.com/cpp/184401976
http://bruscy.republika.pl/pages/przemek/java_not_really_faster_than_cpp.html
http://en.wikipedia.org/wiki/Comparison_of_Java_and_C%2B%2B

Ghost

Title: Re: Java Applets
Post by: Gan on February 13, 2009, 09:45:23 PM
Hmm. Both of these articles are contradicting each other. Either one could be correct, though I guess we will never truly know.

Also, I'm making some progress on Java mouse/keyboard input.

-Gandolf
Title: Re: Java Applets
Post by: GMG Tim on February 13, 2009, 09:50:41 PM
I think the general consensus is that Java is slower than C++, but offers the advantage of easy cross-compatibility between OSes. C++ also is slightly more complicated to learn, but yields faster programs.

If we were talking about embedded systems, C++ would win hands down just because of the sheer amount of overhead required for Java.

Ultimately it doesn't matter for the kind of stuff we're doing here at the GMG. I don't think anybody here really cares if we can get in one more calculation in a cycle. However these things matter when you're studying computers and how to make them faster.

Ghost
Title: Re: Java Applets
Post by: WarHampster on February 13, 2009, 09:53:42 PM
Am I the only one here who hates object oriented code?
Title: Re: Java Applets
Post by: Gan on February 13, 2009, 10:32:49 PM
I simply love it, my life is a whole lot easier because of it.

By the way, I've added a movement demo on the project site:
http://web.mac.com/avisaria/ProjectPage/


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on February 13, 2009, 10:43:48 PM
In my opinion it just makes everything unnecessarily complicated and cryptic, but whatever.
Title: Re: Java Applets
Post by: Gan on February 17, 2009, 07:22:00 PM
Hey guys, update. I tried my hand at making a tile engine from scratch, what do you guys think? Do you guys notice that the character is attached to a grid?
http://web.mac.com/avisaria/ProjectPage/


-Gandolf
P.S. Are there any flickers or laggy-ness to you guys?
Title: Re: Java Applets
Post by: WarHampster on February 17, 2009, 08:27:59 PM
For me, the player is constantly flickering and changing speed...
Title: Re: Java Applets
Post by: Gnome on February 17, 2009, 09:04:52 PM
I think the speed goes with the tile, but the flickering is annoying
Title: Re: Java Applets
Post by: GMG Tim on February 18, 2009, 02:52:32 AM
Quote
For me, the player is constantly flickering and changing speed...

I believe Gan was trying to demo different textures for different tiles. The flickering  died off for me after playing for about 10 seconds-- weird. Looks good!

Ghost
Title: Re: Java Applets
Post by: Gan on February 18, 2009, 07:25:52 AM
I'll look into the flickering, but it seems that there are no lag issues.

Light green tile - Walk regular
Dark green tile - Slower walk
Mountain tile - Can't walk on


-Gandolf
Title: Re: Java Applets
Post by: Gan on February 21, 2009, 05:10:42 PM
Hey, added a scrolling tile engine to my projects list, check it out:
http://web.mac.com/avisaria/ProjectPage/


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on February 21, 2009, 05:32:12 PM
There's still some random flickering, and the first time you walk into the mountains from below you go through them... but good job :P

What are you using to learn java? I'm getting bored of just making bank accounts and stuff in class...
Title: Re: Java Applets
Post by: Gan on February 21, 2009, 06:06:05 PM
I used these tutorial sites to learn, now I've learned all I need. Just up to making any ideas I have...

Main tutorial: http://www.javacooperation.gmxhome.de/TutorialStartEng.html
Another tutorial: http://www.dgp.toronto.edu/~mjmcguff/learn/java/


-Gandolf
Title: Re: Java Applets
Post by: Silverwind on February 21, 2009, 06:19:47 PM
Wow, that first tutorial is cool. I especially like the random landscape generator; the concept might also work for a random dungeon generator with a bit of tweaking.
Title: Re: Java Applets
Post by: Gan on March 28, 2009, 03:11:17 PM
Hey guys, I scoured google until I could find an amazing set of tutorials for Xcode that could teach me everything I would ever learn. I found it in 30 seconds. Besides that, I went through a couple tutorials with great ferocity, intently trying to memorize everything my eyes laid upon. Finally after learning a bit about C language and syntax, I opened Xcode, set specified preferences and was about to open a new cocoa app when...

...I saw another application type. Java Signed Applet! Sorry Netbeans, my heart now belongs to another...


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on June 03, 2009, 06:07:55 PM
Quick question for Gandolf (or anyone else who knows Java):

Will I be shot for making non-constant data static? I mean making a variable static and then using it with static methods as if it were a normal instance variable. Everything seems to say that this is unusual and not recommended... why?
Title: Re: Java Applets
Post by: Gan on June 03, 2009, 07:37:10 PM
Yeah, that method isn't so good. It would be better to create a new instance of the class with a non-static version of that variable within the Main static method. It would make your life much easier.

Here is an example of something I would do:
Main Class
Code: [Select]
public class Main {
    public Main() {
    }
    static Main main = new Main();
    public MainScreen mainscreen;

    public static void main(String args[]) {
        main.mainscreen = new MainScreen(main);
    }
}
MainScreen Class
Code: [Select]
import java.io.*;
import java.net.*;
import java.lang.Thread;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.lang.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.util.List;
import java.util.*;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.geom.*;

public class MainScreen extends javax.swing.JFrame implements Runnable {
    public Runnable runnable = this;

    // Create the thread supplying it with the runnable object
    public Thread Thread = new Thread(runnable);
    //The mouse Input
    public int mx,  my;  // the mouse coordinates
    public boolean isButtonPressed = false;
    //Keyboard input
    public boolean[] keys = new boolean[120];
    public String pressed = "";

    public void run() {
        while (true) {
            canvas1.repaint();
            try {
            Thread.sleep(50);
            }catch (Exception e){}
        }
    }
    public MainScreen() {
    }
    Main main;

    public MainScreen(Main main) {
        this.main = main;
        initComponents();
        this.setVisible(true);
        Thread.setDaemon(true);
        Thread.setPriority(Thread.MIN_PRIORITY);
        Thread.start();
        canvas1.requestFocus();
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    public java.awt.Canvas canvas1;
    private javax.swing.JButton jButton1;
    // End of variables declaration
}

class GCanvas extends Canvas {
    //For Double Buffering

    private Image dbImage;
    private Graphics dbg;
    public MainScreen main;
    public Graphics2D g2;
    AffineTransform affineTransform = new AffineTransform();
    Dimension d;

    public GCanvas(MainScreen main) {
        this.main = main;
    }

    public void paint(Graphics g) {
        g2 = (Graphics2D) g;
        d = this.getSize();

        g2.setColor(Color.RED);
        g2.drawString("hi", 100 ,100);
    }
}

You see, I have my blank Main class which is static, inside it's static-ness; I have it create a non-static instance the the Application window, "Main Screen". On MainScreen is a canvas I made which will display the text, "Hi". It updates the canvas every few milliseconds. If you copy the code exactly, it won't work because I erased a bunch of Gui stuff that hogs space when posted, though if you copy the way I set it up; it will work wonderfully for you.


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on June 03, 2009, 11:22:07 PM
I understand that... but why are static variables bad? Do they use tons of memory or something?
Title: Re: Java Applets
Post by: Gan on June 04, 2009, 11:29:31 AM
Hmm. I'm unsure, haven't thought too much about that. I think it's probably the way it's set up that static variables won't do most things you want to do.

I'm self taught under google, I won't know too many of the best methods or the reasons for the best methods. You should try asking a professional on the official Java forum if the question bugs you too much.


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on June 04, 2009, 12:31:23 PM
I wrote my port of the RPG engine using tons of static variables and my computer science teacher was fine with it, so I'm not going to worry :P
Title: Re: Java Applets
Post by: Gan on June 04, 2009, 01:32:35 PM
Could you post it here? I would love to feast my eyes upon it.


-Gandolf
Title: Re: Java Applets
Post by: WarHampster on June 04, 2009, 06:20:00 PM
Yeah, I'll clean it up a bit and post it.