Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 890245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:42:04+00:00 2026-05-15T13:42:04+00:00

I seem to be having a strange issue with a 2D game I’m working

  • 0

I seem to be having a strange issue with a 2D game I’m working on. In order to determine if my playable character sprite lands on a platform I first do an if statement checking CGRectIntersectsRect and once I’ve determined that the player sprite and platform sprite have intersected, I then check to make sure that the center point (plus half the player’s height) are above the platform, if it is, I then set the player’s ‘y’ velocity to zero.

playerVelocity.x=5;

playerVelocity.y+=gravity;

if (CGRectIntersectsRect([turtle getBounds], [platform getBounds])) {

 if ([player getPosition].y>p.position.y+([player getBounds].size.height/2)) {
  if (playerVelocity.y>0) {
   playerVelocity.y=0;
   inJump=NO;
  }

 }else {
  inJump=YES;
 }
}

[player setPosition:CGPointMake([player getPosition].x+playerVelocity.x, [player getPosition].y-playerVelocity.y)];

Most of the time this code works over the game cycle, however every now and then, the second “if statement” is disregarded and my player sprite passes through the platform. I’m building this game in OpenGL ES 1.1 with a custom sprite class.

Any insight into this issue would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:42:05+00:00Added an answer on May 15, 2026 at 1:42 pm

    One thing to check is to make sure that the Player doesn’t really pass through the platform. How tall is the platform? If the platform height isn’t much, then the player could be above the platform (in one frame) and then in the next frame (player.y + playerVelocity.y) more than halfway through the platform on the other. Which would mean that it would never “hit” the platform even though it seems visually like it did.

    One thing you can do is to print out using an NSLog() the values. this way when you miss, you can check the logs to see what the data values were that missed.

    There are many ways to deal with “landing on platforms”. One is to make sure that the character has reached a high enough altitude to be “above” the platform, and then if it ever crosses then you reset its location to be on the platform.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seem to be having an issue with std::auto_ptr and assignment, such that the object
i'm having an issue with creating a query in oracle which doesnt seem to
I'm having a problem with my Seam code and I can't seem to figure
I seem to be missing something about LINQ. To me, it looks like it's
There seem to be many ways to define singletons in Python. Is there a
I seem to remember reading something about how it is bad for structs to
I seem right now to be embroiled in a debate with another programmer on
I seem to make this mistake every time I set up a new development
I seem to always have problems with converting data to and from XML in
There seem to many ways to skin this particular cat - but which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.