Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to fix this glitch in my 2D platformer?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 nicksaiz65   Members   -  Reputation: 200

Like
1Likes
Like

Posted 22 November 2012 - 03:49 PM

Hi, guys. I just recently finished a level editor for my 2D platformer. I am now working on a program that will actually play the levels that I have created. However, once I started making the camera system, I began to have problems. I want the camera to constantly keep the player in the center of the screen. The screen is 1280 pixels wide. I am trying to always keep the player's x value(represented by player\x#) at 640. So, optimally, the player will always stay at that position. As the player moves, cameraX will keep increasing, and we can scroll the map. I am programming in Blitz Plus. Here's my code for trying to keep the player at the center of the screen:



player\xCameraBoundingBox# = player\x# + 640
If player\xCameraBoundingBox# > 1280 ;if this box has passed the edge of the screen
cameraX = cameraX + (player\xCameraBoundingBox# - 1280) ;add it to camera x
player\x# = player\x# - (player\xCameraBoundingBox# - 1280)
EndIf



However, this poses some problems. Sometimes when the player tries to make a jump, they will be "pushed" back and fall to their death. However, if I don't tell the game to keep the player at the center of the screen, the player will eventually be able to run off the screen, or they will be pressed against the edge of the screen and will not be able to see anything that is coming.

Do you guys have any ideas on how to fix this problem? Any ideas would be appreciated. Thanks.

Here's a link to an article that shows what kind of camera system I am trying to make. I am trying to make a platform-locked camera system.
http://soherearemyid...er-cameras.html
I am the man who will become the pirate king!

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 8178

Like
1Likes
Like

Posted 24 November 2012 - 02:14 AM

Wouldn't it make more sense to let the player move freely, and then simply render the world with world coordinates offset in such a way that the player would always end up drawn in the middle of the screen? This way you avoid ugly "stay in the center" hacks (and as a bonus, this feature can be easily toggled on and off)

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 nicksaiz65   Members   -  Reputation: 200

Like
0Likes
Like

Posted 24 November 2012 - 09:21 AM

Bacterius, sorry if this is a stupid question, but could you please post some pseudocode? Because if I just keep letting player\x# increase, wouldn't the player eventually run off the edge of the screen?
I am the man who will become the pirate king!

#4 FLeBlanc   Crossbones+   -  Reputation: 3081

Like
1Likes
Like

Posted 24 November 2012 - 09:55 AM

If the player is allowed to run off the edge of the map, how is that the camera's fault? The camera should be strictly an observer: it observes the player's position and uses that position value to center its view upon. If you allow the camera to modify the player's position, rather than leaving that up to the player's logic and the constraints on motion provided by the level setup and geometry, then you are just asking for trouble. The camera should not be an active participant in game logic. It's just a watcher.

#5 r1ckparker   Members   -  Reputation: 379

Like
2Likes
Like

Posted 26 November 2012 - 01:56 AM

I think his problem is that the world is in 2d so you have to calculate where on screen you should be drawing everything

So the players's x would increase when you press 'right', so playerx could be 3000 for example (the player is 3000 units to the right of his starting point)

therefore the player would always be drawn at screen co-ordinate 640 but the world would be offset around him - the draw window (what is drawn on screen) would be playerx-640 to playerx+640

so you would look up your level map and draw everything from 3000-640 to 3000+640.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS