Really long post-mortem now but the reason you struggled was from the design of the Player class - on creation it simply sets its x and y to half of the GamePanel's width and height inside of the constructor. Hopefully future viewers find this helpful.
at 10 mins, I have a problem im player... //right if(Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset, iY + (int)GameState.yOffset + 2), b[1]) || Collision.playerBlock(new Point (iX + width + (int)GameState.xOffset, iY + height + (int)GameState.yOffset - 1), b[i][j])) { right = false; the player Block at the top is wrong.
I know this is a very old comment and you probably have already solved it. But, anyway, if someone else has this problem, it might be because of the line: topCollision = false; Check if you put it in the right place. It should stay *outside* of the for loops.
sorry if this is too late but when you paused the video to figure out what was wrong when you played it again I did what you did and my player goes invisible/blank. Please Help Me...
+Jonathan Persgarden ok I did that and now I get an error: Exception in thread "Thread-1" java.lang.NullPointerException at com.philip.platformer.physics.Collision.playerBlock(Collision.java:10) at com.philip.platformer.entities.Player.tick(Player.java:46) at com.philip.platformer.gamestate.Level1State.tick(Level1State.java:33) at com.philip.platformer.gamestate.GameStateManager.tick(GameStateManager.java:17) at com.philip.platformer.main.GamePanel.tick(GamePanel.java:71) at com.philip.platformer.main.GamePanel.run(GamePanel.java:51) at java.lang.Thread.run(Unknown Source) (I have changed the package names)
Really long post-mortem now but the reason you struggled was from the design of the Player class - on creation it simply sets its x and y to half of the GamePanel's width and height inside of the constructor. Hopefully future viewers find this helpful.
The paremeter of the player's constructor is width, height you are entering 0 and -100 and you thought it was x, y not width, height.
at 10 mins, I have a problem im player... //right
if(Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset, iY + (int)GameState.yOffset + 2), b[1])
|| Collision.playerBlock(new Point (iX + width + (int)GameState.xOffset, iY + height + (int)GameState.yOffset - 1), b[i][j])) {
right = false;
the player Block at the top is wrong.
after 5 years I'm here to help.
if(Collision.playerBlock(new Point(iX + width + (int)GameState.xOffset, iY + (int)GameState.yOffset + 2), b[I][j])
|| Collision.playerBlock(new Point (iX + width + (int)GameState.xOffset, iY + height + (int)GameState.yOffset - 1), b[i][j])) {
right = false;
}
how come you dont have way more like? nice vid bro.
completely failed me. the player just falls through every thing
I know this is a very old comment and you probably have already solved it. But, anyway, if someone else has this problem, it might be because of the line:
topCollision = false;
Check if you put it in the right place. It should stay *outside* of the for loops.
sorry if this is too late but when you paused the video to figure out what was wrong when you played it again I did what you did and my player goes invisible/blank.
Please Help Me...
+Philip Anderson have you set negative values in the player constructor as pj did, because those are the size of the player and should be positive :)
+Jonathan Persgarden ok I did that and now I get an error:
Exception in thread "Thread-1" java.lang.NullPointerException
at com.philip.platformer.physics.Collision.playerBlock(Collision.java:10)
at com.philip.platformer.entities.Player.tick(Player.java:46)
at com.philip.platformer.gamestate.Level1State.tick(Level1State.java:33)
at com.philip.platformer.gamestate.GameStateManager.tick(GameStateManager.java:17)
at com.philip.platformer.main.GamePanel.tick(GamePanel.java:71)
at com.philip.platformer.main.GamePanel.run(GamePanel.java:51)
at java.lang.Thread.run(Unknown Source)
(I have changed the package names)