[gameprogrammer] Re: A newbie Java Question - GUI/Animation etc...

Hi Tom,

I absolutely agree.  This approach would be totally inappropriate for
anything more than a simple game.  My project is a simple project with
little collision detection.  I have only been learning Java for a
couple of weeks and I don't want dive straight into the more complex
stuff.  It is actually a Tetris Game.  I have written many in the past
in C++, VB, JavaScript even.  With a new language I want to get to
grips with it without the strain.  With a simple project like this I
can learn a lot about the language and its APIs.  GUI Display, Timers,
Input Methods, Data Types, Etc. Etc.  When I'm done and the project is
completed I will be more comfortable with Java as a whole and therefor
more confident in my ability to try something more complex.

I know Tetris style games are two-a-penny but sometimes re-inventing
the wheel is the best way to get to know the tools at your disposal.

Regards

Richard

On 08/02/2008, Tom Clifford <tjclifford@xxxxxxxxx> wrote:
> From looking at what different people are doing,
> my biggest question is:
>
> If you are using your own paint routines, and
> using the 'Graphics g' to do all of your drawing
> (which would be the fastest), when you start to
> develop 3d games and use BSP trees and files, with
> the accompanying collision checking routines, etc.,
> would not this approach increase the complexity
> (and concomitant propensity for bugs) in
> development ?
>
> With simple games it would not be an issue, but for
> games with any complexity, with behaviors that need
> to be triggered when the player POV enters or exits
> a given region, the techniques involved could get
> very difficult;  I'm a big fan of using layers
> to avoid the difficulties inherent in arbitrary
> geometries and behaviors.
>
> If a developer can use something like Xith3d
> (xith3d.org) to avoid re-inventing the wheel,
> I'm for it.
>
> Tom C
>
> --- richard sabbarton <richard.sabbarton@xxxxxxxxx>
> wrote:
>
> > Hi Steve,
> >
> > Thanks for sending that through.  It looks exactly
> > what I am looking
> > for and I will certainly make use of it.
> >
> > Regards
> >
> > Richard
> >
> > On 06/02/2008, Stephen & Kelly
> > <gp@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> > > Richard,
> > >
> > > All you need to do in Java to get double-buffering
> > is something like:-
> > >
> > >
> > > public class MyClass extends JFrame { // You can
> > extend any Component IIRC
> > >
> > >  private BufferStrategy BS;
> > >
> > >    public MyClass() {
> > >               this.createBufferStrategy(2); //
> > Number of buffers
> > >              BS = this.getBufferStrategy();
> > >
> > >    }
> > >
> > >    private mainGameLoop() {
> > >       while (true) {
> > >          Graphics g = BS.getDrawGraphics();
> > >          // Do all drawing using g
> > >          BS.show();
> > >       }
> > >    }
> > >
> > > }
> > >
> > > That's all there is to it, and you don't need to
> > download any API's or
> > > anything.  Good luck with the Java; I think it's
> > great for games.
> > >
> > > Steve
> > >
> > >
> > >
> > > richard sabbarton wrote:
> > > > Hi Tom,
> > > >
> > > > I downloaded the Java3D API from Sun.  It looks
> > good but I think it
> > > > was a bit much for what I was looking for.
> > Anyway, after a little
> > > > further digging I managed to work out how to do
> > what I was trying to
> > > > do.
> > > >
> > > > The key to getting rid of the flicker was not
> > using the paint()
> > > > function but instead, using my own.
> > > >
> > > > Firstly, I created a new Image and then obtained
> > the Graphics
> > > > interface for the image.  This gave me my
> > offscreen location to
> > > > assemble my GUI.  I then use this image and draw
> > it to the Graphics
> > > > interface of my Applet
> > > >
> > > > // Variables and members
> > > > Image offScreenImage;
> > > > Graphics offScreenGraphics;
> > > > Graphics onScreenGraphics;
> > > >
> > > > In the init function I run the following:
> > > >
> > > >     offScreenImage = createImage( width, height
> > );
> > > >     offScreenGraphics =
> > offScreenImage.getGraphics();
> > > >     onScreenGraphics = this.getGraphics();
> > > >
> > > >
> > > > I then setup a timer to keep the screen
> > up-to-date every xxx
> > > > milliseconds which basically runs the following:
> > > >
> > > >     // Draw everything I need to my offscreen
> > Graphics Interface
> > > >     offScreenGraphics.drawImage( etc. etc. etc.
> > );
> > > >     offScreenGraphics.drawImage( etc. etc. etc.
> > );
> > > >     offScreenGraphics.drawImage( etc. etc. etc.
> > );
> > > >
> > > >     // Then draw the whole thing to screen with
> > the Image Interface
> > > >     onScreenGraphics.drawImage(offScreenImage,
> > xxx , yyyy , this );
> > > >
> > > > Seems to work quite well for simple graphics and
> > GUI etc.  If I want
> > > > anything more complex then I will go down the
> > Java3D route but for now
> > > > this will do.
> > > >
> > > > Regards
> > > >
> > > > Richard
> > > >
> > > >
> > > >
> > > > On 04/02/2008, Tom Clifford
> > <tjclifford@xxxxxxxxx> wrote:
> > > >
> > > >> Java has it's own Java3D interface, found at:
> > > >>
> > > >> http://java.sun.com/products/java-media/3D/
> > > >>
> > > >> It allows you to do what is called active
> > rendering,
> > > >> which is similar to the c/c++ WinMain/WndProc
> > loops,
> > > >> that uses double-buffering,
> > > >> or you can create the objects you want and
> > allow
> > > >> Java3D to do the looping for you, while doing
> > > >> animation with their Behavior objects.
> > > >>
> > > >> There are some good java examples with source
> > > >> code, at Killer Game Programming with Java, by
> > > >>  Andrew Davison
> > > >>  O'Reilly, May 2005
> > > >>  ISBN: 0-596-00730-2
> > > >>  http://www.oreilly.com/catalog/killergame/
> > > >>  Web Site for the book:
> > > >>  http://fivedots.coe.psu.ac.th/~ad/jg
> > > >>
> > > >> code downloads and instructions at:
> > > >>
> > > >> http://fivedots.coe.psu.ac.th/~ad/jg/code/
> > > >>
> > > >> Tom C.
> > > >>
> > > >>
> > > >> --- richard sabbarton
> > <richard.sabbarton@xxxxxxxxx>
> > > >> wrote:
> > > >>
> > > >>
> > > >>> Hi Guys,
> > > >>>
> > > >>> In C++ on windows I would use animation by
> > creating
> > > >>> a compatible
> > > >>> device context in memory with
> > CreateCompatibleDC().
> > > >>> I would write my
> > > >>> game and all of its elements to the MemoryDC
> > and
> > > >>> then use something
> > > >>> like BitBlt() to push it to my main DC.
> > > >>>
> > > >>> I have recently started learning Java and I
> > want to
> > > >>> perform a similar
> > > >>> function.  I want to write all of the elements
> > to
> > > >>> memory and then
> > > >>> transfer it to the screen every x
> > milliseconds.
> > > >>> This is to eliminate
> > > >>> flicker etc.
> > > >>>
> > > >>> I have been looking online through tutorials
> > etc.
> > > >>> and I can't seem to
> > > >>> find a description of how to do this.  Do I
> > need to
> > > >>> use java.awt or
> > > >>> should I use javax.swing.
> > > >>>
> > > >>> Any thoughts on how to do this or suggestions
> > on
> > > >>> greating a game
> > > >>> display in Java?
> > > >>>
> > > >>> Initially this is for display in an Applet in
> > a web
> > > >>> page.
> > > >>>
> > > >>> Regards
> > > >>>
> > > >>> Richard
> > > >>>
> > > >>> ---------------------
> > > >>> To unsubscribe go to
> >
> === message truncated ===
>
>
>
>      
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.  
> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: