Results 1 to 4 of 4
- 02-29-2012, 08:49 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 13
- Rep Power
- 0
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; }
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.
- 02-29-2012, 09:48 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
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)
- 02-29-2012, 10:00 PM #3
Member
- Join Date
- Jan 2012
- Posts
- 13
- Rep Power
- 0
Re: Flickering, need help finding a way to get it out
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?
- 02-29-2012, 10:38 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,716
- Rep Power
- 19
Similar Threads
-
Item Flickering
By vincy in forum CLDC and MIDPReplies: 0Last Post: 10-25-2011, 08:48 AM -
Screen Flickering
By dewitrydan in forum New To JavaReplies: 2Last Post: 08-17-2010, 08:45 PM -
flickering problem
By dimril in forum Java 2DReplies: 5Last Post: 06-11-2010, 09:52 AM -
SWT ExpandBar flickering
By Tomasz Wroniak in forum SWT / JFaceReplies: 0Last Post: 12-02-2009, 01:23 PM -
Applet flickering
By samson in forum Java 2DReplies: 3Last Post: 09-21-2007, 11:51 PM
Bookmarks