Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 58
  1. #21
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    ah found it,

    java.lang.IllegalStateException: Component must have a valid peer
    at java.awt.Component$FlipBufferStrategy.createBuffer s(Component.java:3982)
    at java.awt.Component$FlipBufferStrategy.<init>(Compo nent.java:3956)
    at java.awt.Component$FlipSubRegionBufferStrategy.<in it>(Component.java:4479)
    at java.awt.Component.createBufferStrategy(Component. java:3833)
    at java.awt.Canvas.createBufferStrategy(Canvas.java:1 94)
    at java.awt.Component.createBufferStrategy(Component. java:3756)
    at java.awt.Canvas.createBufferStrategy(Canvas.java:1 69)
    at TRYstrat.<init>(TRYstrat.java:24)
    at TRYstrat.main(TRYstrat.java:52)

  2. #22
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Does the Canvas object have a peer it can use to get what it needs from the OS? It may not get that until its visible.

    Look at the code example for the BufferStrategy class in the API doc.
    Last edited by Norm; 06-14-2012 at 11:16 PM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #23
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    setting it visible first does fix that problem, but when it draws the rectangle it doesn't erase its previous drawing. so it ends up looking like a bar, why does it do this?

    Java Code:
    import java.awt.*;
    import java.awt.image.BufferStrategy;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.util.Timer;
    import java.util.TimerTask;
    import java.awt.Rectangle;
    public class TRYstrat extends Fram
    {
        Panel base = new Panel();
        Canvas canvas = new Canvas();
        Timer t = new Timer();
        int x=50,y=50;
        BufferStrategy strategy;
        TRYstrat()
        {
            super("TRYstrat");
            setSize(800,600);
            //setIgnoreRepaint(true);
            add(base);
            //canvas.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
            setIgnoreRepaint(true);
            base.add(canvas);
            canvas.setSize(500,500);
            canvas.setIgnoreRepaint(true);
            //setUndecorated(true);
            setVisible(true);
            canvas.createBufferStrategy(2);
            strategy = canvas.getBufferStrategy();
            t.schedule(new TimerTask()
                        {
                            public void run()
                            {
                                strategy = canvas.getBufferStrategy();
                                do
                                {
                                    do
                                    {
                                        Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
                                        render(g);
                                        g.dispose();
                                    }while(strategy.contentsRestored());
                                    strategy.show();
                                }while(strategy.contentsLost());
                            }
                        },1000,500);
            
            //pack();
        }
        public void render(Graphics2D g2)
        {
            x+=10;
            g2.draw(new Rectangle(x,y,50,50));
        }
        public static void main(String[] args)
        {
            TRYstrat a = new TRYstrat();
        }
    }

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    it doesn't erase its previous drawing
    Why do you think it should erase previous drawings? Some people want them kept.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    What I mean is I want it to seem as if the rectangle is moving, not draw it over and over again so it looks like a long bar. Honestly I could very much use this problem some time later, I just wanna know what is causing it.

  6. #26
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    What would erase what was drawn previously? Why wouldn't it remain drawn on the graphics context?
    If you don't understand my response, don't ignore it, ask a question.

  7. #27
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    it just always has erased it up until now, how do I make it so it doesn't remain. It has allways just erased it for me when I used repaint...so what do I do now?

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Read the API doc for BufferStrategy, VolatileImage etc classes. The life of images is discussed there.

    how do I make it so it doesn't remain
    Use one of the clear methods.
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    I hope you don't mean that I have to clear each individual shape do you, as in clearRect()? Is there some method for clearing the entire screen or canvas?

  10. #30
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Try reading the API docs for the classes you are using. The methods shown there should tell you what can be done.
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    Dude I dug through the api for graphics2D and canvas, I see no method that fits what I need. I see some people just paint a huge rectangle over everything that was on the screen but this seems so unnecessary
    Last edited by PRW56; 06-15-2012 at 08:40 PM.

  12. #32
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    What's wrong with the rectangle over the top of what you want cleared?

    What kind of method are you looking for?
    If you don't understand my response, don't ignore it, ask a question.

  13. #33
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    there is nothing wrong with it, I just assumed there was something more effecient. Anyway it works, now back to the image dilema. I draw my image to the screen, it is a stick person. This image is has a white background, which is drawn with the stick person. I need a way to get rid of this background, but all images must be drawn with whitespace or whatever else it has as a background. I tried drawing an image with an opaque background in photoshop, it made no diference. How do I draw my images with an opaque background. Im sorry if the question is badly worded but its hard for me to describe.

  14. #34
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Can you post a small complete program that compiles, executes and shows the problem?
    If you don't understand my response, don't ignore it, ask a question.

  15. #35
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    I was writing that program, but thankfuly I remembered that it wouldn't work. I would need to draw the image myself, so that means you couldn't see it. My problem is I have a white background of an image drawn with the image. I don't want this white background there, any methods in java that can make this so?

  16. #36
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Sorry, without an example I'm having a hard time seeing what you are talking about. if you use fillRect before drawing a stick figure, you can set its background.
    If you don't understand my response, don't ignore it, ask a question.

  17. #37
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    open up paint and draw a circle, save the picture, when you open it you see all that excess white around it? that is what Im talking about, because when you draw these in java all that white crap is there. I want to get rid of that white crap.

  18. #38
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    fill it with the color you want. Crop it to the size you want.
    If you don't understand my response, don't ignore it, ask a question.

  19. #39
    PRW56 is offline Member
    Join Date
    Mar 2012
    Posts
    75
    Rep Power
    0

    Default Re: game engine trouble

    no matter what color it is or how big the picture is, the empty space will still be there. If this sprite is moving over a background this will screw up the way it looks. I need a way to get rid of this space.

  20. #40
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: game engine trouble

    Post a small sample program that shows what is happening.

    Set the Alpha property of the pixels to transparent
    If you don't understand my response, don't ignore it, ask a question.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Easy Clip2D Game Engine now posted
    By rdjava in forum Reviews / Advertising
    Replies: 3
    Last Post: 06-03-2011, 05:24 PM
  2. Easy Clip2D Game Engine now posted
    By rdjava in forum Java Gaming
    Replies: 2
    Last Post: 06-03-2011, 05:18 PM
  3. Replies: 1
    Last Post: 06-02-2011, 09:29 AM
  4. Game Engine in Java, is it practical idea?
    By chan_nguyen in forum New To Java
    Replies: 2
    Last Post: 09-14-2010, 03:20 PM
  5. Crate Game Engine 20080323
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 03-25-2008, 04:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •