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

  • Home
  • SEARCH
  • 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 8220631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:35:41+00:00 2026-06-07T13:35:41+00:00

I have tried many different techniques of applying a realistic looking gravity feature in

  • 0

I have tried many different techniques of applying a realistic looking gravity feature in my game but have had no luck so far. I plan on offering a 100 point bounty on this for someone who can show me or (share) some code that applies gravity to a CCSprite in Cocos2D.

What I have done so far has just been ugly or unrealistic and I have asked in many different places on what the best approach is but I just have not found any good looking gravity techniques yet.

Anyway, can anyone offer some tips/ideas or their approach only applying gravity to a CCSprite in Cocos2D without using a physics engine?

Thanks!

  • 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-06-07T13:35:43+00:00Added an answer on June 7, 2026 at 1:35 pm

    A effective approach without having to explicitly use any physics engine is to step the velocity and position of your sprite manually in your update loop. This is essentially Euler Integration.

    // define your gravity value
    #define GRAVITY -0.1
    
    // define a velocity variable in the header of your Game class/CCSprite Subclass (neater)
    float velocity_y;
    
    -(void) update: (ccTime) dt
    {
        // Step the y-velocity by your acceleration value (gravity value in this case)
        velocity_y += GRAVITY *dt; // drop the dt if you don't want to use it 
    
        // Step the position values and update the sprite position accordingly
        sprite.position.y += velocity_y* dt; // same here
    }
    

    In the code snippet above, I defined a velocity_y variable to keep track of my sprite’s current velocity along the y-direction. Remember to initialize this value to 0 in your init method.

    Next comes the crux of Euler. At every time step:

    1. Advance your velocity by your acceleration (which is your gravity) multiplied by dt to find your new velocity.
    2. Advance your position by your newly computed velocity value multiplied by dt to find your new position.

    You can experiment whether using delta-time or not (see LearnCocos2D’s excellent comment on the cons of using it) works for your game. While multiplying by delta-time allows your object motion to more accurately take into account varying framerates, as LearnCocos2d pointed out, it might be wise to avoid using it in a real-time game where system interrupts (new mail, low battery, ads pop-out) can occur and subsequently cause the game simulation to jump forward in an attempt to make up.

    So if you are dropping the dt, remember to tweak (scale down) your GRAVITY value accordingly to retain the right feel, since this value is no longer multiplied by the value of delta-time (which is ~ 1/60).

    Aditional Tip: To apply an impulse to move the sprite (say via a swipe), you can affect the velocities directly by changing the values of velocity_x (if you have this) and velocity_y.

    I have used this approach in my games, and it works very well. hope it helps.

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

Sidebar

Related Questions

Yes, I have searched and tried many techniques, but nothing seems to work. Here
http://www.example.com/http://www.test.com I have tried many different methods using .htaccess with no luck. I need
I have tried many different languages and copied various examples, but none of my
I have tried many different mapping configurations but continue to generate exceptions or create
i need help with this regex pattern. I have tried many different patterns but
I am using jQuery fullcalendar plugin , I have tried altering this many different
I have tried many permutations but they all don't seems to work well. Am
Hello friends I have tried many times but I am not successful than please
This should be really simple, but I have tried many solutions posted on the
I tried many ways to solve this problem but none works. suppose I have

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.