Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2d tiled scrolling game flickering and collision problem  (Read 1958 times)
0 Members and 1 Guest are viewing this topic.
Offline zakur0

Junior Newbie





« Posted 2012-06-06 10:51:23 »

]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)  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
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

  
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
  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 :/
Offline ReBirth
« Reply #1 - Posted 2012-06-06 10:57:07 »

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.

Offline zakur0

Junior Newbie





« Reply #2 - Posted 2012-06-06 11:09:18 »

ok will fix it straight away no the one is the real map the other is the one that is drawn on screen
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-06-06 12:37:08 »

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

Offline zakur0

Junior Newbie





« Reply #4 - Posted 2012-06-06 12:59:18 »

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
Offline ReBirth
« Reply #5 - Posted 2012-06-06 13:04:17 »

Why you set mario's x to 0?

Offline zakur0

Junior Newbie





« Reply #6 - Posted 2012-06-06 15:17:41 »

no thats no the marioRect.x that is the +x that will be added to its current position
Offline ReBirth
« Reply #7 - Posted 2012-06-07 14:01:17 »

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

Offline Ultroman

JGO Knight


Medals: 25
Projects: 1


Snappin' at snizzes since '83


« Reply #8 - Posted 2012-07-14 19:02:04 »

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

- Jonas
Offline ReBirth
« Reply #9 - Posted 2012-07-15 03:09:18 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Sickan

Senior Member


Medals: 9



« Reply #10 - Posted 2012-07-17 08:09:18 »

One week already passed, either he's found the solution or given up.
> a month.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!