2d tiled scrolling game flickering and collision problem

]Hello,
i m making a tiled super mario game and i dont really have much experience on game development.The game is going quite well and it works all fine but i have some flickering when the map moves and also at collision on the x-axis although the character stops for awhile if you keep pressing to move forward you can pass through.

I have 2 maps[][] in the game and if the character moves after the half of the screenWidth the dx(difference in x) is summed and the offset is created(by dividing with the tile size) then all the image from the real map[][] of the game are passed to the map[][] of the screen

this is the checkCollision on x(on y there is a gravity method)

private void checkForCollision(){
    	 for(int i = 0; i <world.NumberTilesWidth; i++){
         	for(int j=0 ; j<world.NumberTilesHeight-2;j++){
         		
            if( world.isSolid[i][j] && marioRect.getBounds().intersects(world.blocks[i][j+1].getBounds()) ){
                  setXDirection(0);
                  
         	  }
            
      
    		 }
         	
    	 }
    }	
    

and this is the movemap method

  public void moveMap(int dx){
		          
		            
		            offset +=  dx;
		            
		         if(offset/16 ==1){
		        	 offset = 0;
		        	 tileoffset ++;
		        	   for(int j=0;j<NumberTilesScreenHeight;j++){
			        		for(int i=0;i<NumberTilesScreenWidth;i++){
			        			{
			        			if(i+offset<=NumberTilesWidth)
			        		 	screenImg[i][j] = blockImg[i+tileoffset][j];
			        		  		}
			        			}
		        	   }
		         }else if(offset/16 ==-1){ 
		        	 offset = 0;
		        	 tileoffset --;
		        	 for(int j=0;j<NumberTilesScreenHeight;j++){
			        		for(int i=0;i<NumberTilesScreenWidth;i++){
			        			{
			        			if(i+offset<=NumberTilesWidth)
			        		 	screenImg[i][j] = blockImg[i+tileoffset][j];
			        		  		}
			        			}
		        	   }
		         }
		       }

can anyone give me a point to fix that flickering stuff :confused:

First, block your posted code on [ code ] tag or use forum’s pastebin.

When you mean passed all real map[][] to map[][], you didn’t draw all of them right? you should only draw what visible.

ok will fix it straight away no the one is the real map the other is the one that is drawn on screen

So make sure your Graphics only draws map as big as your screen. Use offset for X.

yeah thats what i m doing it works but it doesnt run smoothly when i move the character it seems like its spiking and it doesnt look all that good.there s also that problem with collision which i really dont understand…although the rectagnles do intersect and i ve set to have the +x(of the character position) become 0 when it does it still passes by

Why you set mario’s x to 0?

no thats no the marioRect.x that is the +x that will be added to its current position

Offset? I don’t really clear about your collision prob.

Is there some way we could get a runnable jar and maybe the full source? This kind of problem can be in several parts of the code. Without seeing what the problem looks like, it’s hard to help

One week already passed, either he’s found the solution or given up.

> a month.