School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,435 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,476 people online right now. Registration is fast and FREE... Join Now!




stuff sticking to walls - graphics problem?

 

stuff sticking to walls - graphics problem?, this is weird =/

jyth

3 Jul, 2009 - 10:21 PM
Post #1

New D.I.C Head
Group Icon

Joined: 29 Jun, 2009
Posts: 23


Dream Kudos: 50
My Contributions
this is in java, drawing on a canvas inside of a jframe

Coding an asteroids game here. The problem is with the asteroids currently. they function normally until they hit a boundary of the drawing area. At this point they tend to stick to the boundary and move along it or suddenly stopping. I've looked at the positions of the asteroids, and they are not changing as they should be when the asteroid gets stuck. Also, they do not get stuck on the right and bottom borders, where the drawing surface does not quite meet the edge of the jframe for some reason. I'm not putting up any code atm, just checking to see if i can get any quick answers, i'll give code when there does not seem to be an easy solution.

Note: the player controlled ship moves around perfectly fine, not attaching to any walls or anything weird when it moves fast, but when the ship is moving slowly it gets stuck to the wall.

I've racked my brains and cannot come up with a solution blink.gif

Going to make a video of this I think.



User is offlineProfile CardPM
+Quote Post


Tom9729

RE: Stuff Sticking To Walls - Graphics Problem?

5 Jul, 2009 - 11:05 AM
Post #2

Debian ninja
Group Icon

Joined: 30 Dec, 2007
Posts: 2,129



Thanked: 53 times
Dream Kudos: 425
My Contributions
Are the asteroids supposed to wrap around when they hit a boundary? This doesn't sound like a graphics problem to me. Please post some code or provide more details if you expect to get any help.
User is offlineProfile CardPM
+Quote Post

jyth

RE: Stuff Sticking To Walls - Graphics Problem?

7 Jul, 2009 - 10:29 AM
Post #3

New D.I.C Head
Group Icon

Joined: 29 Jun, 2009
Posts: 23


Dream Kudos: 50
My Contributions
http://www.youtube.com/watch?v=UsUKEtO_LIY
Here is a video of the problem. See how the asteroids attach themselves to the top and left sides.

For now the asteroids arn't supposed to wrap around, just move offscreen then despawn. This is working allright, if only the asteroids would make it offscreen.

CODE
this.setSize(dimensions);
        setIgnoreRepaint(true);
        setBackground(Color.black);
        frame = new JFrame();
        frame.setIgnoreRepaint(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle(window_name);
        frame.setFocusTraversalKeysEnabled(false);
        frame.add(this);
        frame.pack();
        frame.setResizable(false);
        frame.setVisible(true);
        keylistener = new BasicKeyListener();
        addKeyListener(keylistener);
        mouselistener = new BasicMouseListener();
        addMouseListener(mouselistener);
        requestFocus();
        createBufferStrategy(buffer_strategies);
        bufferStrategy = getBufferStrategy();
        graphics = (Graphics2D) bufferStrategy.getDrawGraphics();


This is the code setting up the jframe and drawing canvas. The asteroids are moving normally everywhere else so I'm thinking everything concerning their velocities and moving is ok. The size i'm working with is 800x600. Is there anything that causes (x,y) co-ordinates to snap to 0?

Let me know if you want any other code.

EDIT: Going to try turning the (x, y) co-ords into doubles.

This post has been edited by jyth: 7 Jul, 2009 - 10:30 AM
User is offlineProfile CardPM
+Quote Post

Tom9729

RE: Stuff Sticking To Walls - Graphics Problem?

7 Jul, 2009 - 02:08 PM
Post #4

Debian ninja
Group Icon

Joined: 30 Dec, 2007
Posts: 2,129



Thanked: 53 times
Dream Kudos: 425
My Contributions
Keep in mind that a pixel is essentially indivisible. I'm pretty sure Java2D only deals with pixels so your (x, y) coords should be integers (ie. you can't have a half pixel).

Could you please post the code where you are updating the asteroid positions, doing collision checking, etc. I'm guessing the problem is there.
User is offlineProfile CardPM
+Quote Post

jyth

RE: Stuff Sticking To Walls - Graphics Problem?

7 Jul, 2009 - 07:52 PM
Post #5

New D.I.C Head
Group Icon

Joined: 29 Jun, 2009
Posts: 23


Dream Kudos: 50
My Contributions
There are no collisions yet. The positions are updated by just adding the velocity on, this addition (for the asteroids) is usually less than one.

Turning the position values into doubles has seemed to work. When rendering I round off, but now I can accuratly add the velocities.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:55AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month