Results 1 to 4 of 4
  1. #1
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Flickering, need help finding a way to get it out

    I've been trying to stop my play( a ball/rectangle for now) from flickering whenever he's colliding with something. It happens because, whenever the player collides with something, I move the play to a location 1 pixel above the thing it's colliding with, and set the gravity to 0. Problem is, when the game sees that the player is no longer colliding with the platform/ground anymore, it re-initiates the gravity. I can't have the player sitting directly on the platform, because when I do, it's always colliding with it, which makes jumping impossible, because it'll turn off the gravity before he moves.

    Things that have to do with gravity (y = 534 is 1 pixel higher than the collision box)
    Java Code:
    		if(Gravity.isOnGround != true){
    			Gravity.getYMomentum();
    		}
    Java Code:
    		if(character.intersects(Ground)){
    			y = 534;
    			Gravity.isOnGround = true;
    			Gravity.timer = 0;
    			Gravity.yMomentum = 0;}else{
    Gravity.isOnGround = false;
    }
    Gravity class
    Java Code:
    public class Gravity {
    	public static boolean isOnGround = false;
    	static int timer = 0;
    	public static int yMomentum = 0;
    	public static void getYMomentum(){
    		//After 13 ticks, yMomentum increases
    		if(timer <= 13){
    			timer++;
    		}else{
    			yMomentum++;
    			timer = 0;
    		}
    	}
    }
    Last edited by Atynine; 02-29-2012 at 08:52 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Flickering, need help finding a way to get it out

    You might find it more straight forward if your game follows real physics rather than this 1px hover thing.

    A collision should be detected not merely when two things are in contact, but rather when they *first* come into contact. You could remember the state of characters (standing, jumping etc) or rely on the fact that when a character collides with the ground there will be some component of relative motion perpendicular to the ground. (which won't exist after the collision)

  3. #3
    Atynine is offline Member
    Join Date
    Jan 2012
    Posts
    13
    Rep Power
    0

    Default Re: Flickering, need help finding a way to get it out

    Quote Originally Posted by pbrockway2 View Post
    You might find it more straight forward if your game follows real physics rather than this 1px hover thing.

    A collision should be detected not merely when two things are in contact, but rather when they *first* come into contact. You could remember the state of characters (standing, jumping etc) or rely on the fact that when a character collides with the ground there will be some component of relative motion perpendicular to the ground. (which won't exist after the collision)
    Thanks for making me realize that. It lead me onto the way I could fix it. First, I made the player move directly on top of the collision box(not 1 pixel higher), and when I want the player to jump, I simply move him up the 1 pixel needed to clear the collision box. Why didn't I think of that before?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: Flickering, need help finding a way to get it out

    Great - I'm glad you've got it sorted out.

Similar Threads

  1. Item Flickering
    By vincy in forum CLDC and MIDP
    Replies: 0
    Last Post: 10-25-2011, 08:48 AM
  2. Screen Flickering
    By dewitrydan in forum New To Java
    Replies: 2
    Last Post: 08-17-2010, 08:45 PM
  3. flickering problem
    By dimril in forum Java 2D
    Replies: 5
    Last Post: 06-11-2010, 09:52 AM
  4. SWT ExpandBar flickering
    By Tomasz Wroniak in forum SWT / JFace
    Replies: 0
    Last Post: 12-02-2009, 01:23 PM
  5. Applet flickering
    By samson in forum Java 2D
    Replies: 3
    Last Post: 09-21-2007, 11:51 PM

Posting Permissions

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