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 8406831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:13:13+00:00 2026-06-09T23:13:13+00:00

I am trying to move sprite on touch moved. but when two sprites is

  • 0

I am trying to move sprite on touch moved. but when two sprites is there i am geting touch of two sprites. that’s why sprites are not moving properly.

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{

if (_mouseJoint != NULL) return;

    UITouch *myTouch = [touches anyObject];
    CGPoint location = [myTouch locationInView:[myTouch view]];
    location = [[CCDirector sharedDirector] convertToGL:location];
    b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);

    for(int i=0;i<[mutArrFixtures count];i++)
    {
        b2Fixture *fixture;
        [[mutArrFixtures objectAtIndex:i] getValue:&fixture];

        if (fixture->TestPoint(locationWorld)){

            for(int j=0; j<[mutArrPaddleBody count]; j++)
            {
                b2Body *body;
                [[mutArrPaddleBody objectAtIndex:j] getValue:&body];
                b2MouseJointDef md;
                if(body == fixture->GetBody())
                {
                    md.bodyA = _groundBody;
                    md.bodyB = body;
                    md.target = locationWorld;
                    md.collideConnected = true;
                    md.maxForce = 1000.0f * body->GetMass();

                    _mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);
                    body->SetAwake(true);
                }
            }
        }
    }
}

i have an array of b2Fixture mutArrFixtures and also an array mutArrPaddleBody of b2body. but in this if i touch on second sprite i get touch on first sprite and second sprite.. two sprites positions are same…

  • 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-09T23:13:14+00:00Added an answer on June 9, 2026 at 11:13 pm

    In touch function, check tag of the sprite. If that is ur right sprite then move. Show me some code that u used for touch movement.

    …….

    Replace these code with next one

                b2Body *body;
                [[mutArrPaddleBody objectAtIndex:j] getValue:&body];
                b2MouseJointDef md;
                if(body == fixture->GetBody())
    

    with

    b2Body* body = fixture->GetBody();
    
    CCSprite *sprite = (CCSprite*)body->GetUserData();
    
    if( sprite && sprite.tag == kTagHero) 
    {
    
    }
    

    Make sure u added tag kTagHero for ur moving sprite.

    ….

    enum gameTag {
      kTagHero = 1001
    };
    

    and assign sprite.tag = kTagHero
    ……

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

Sidebar

Related Questions

I'm trying to move a sprite in a QGraphicsView. I use : connect(timer, SIGNAL(timeout()),
I am trying to move some files in python, but they have spaces in
I am trying to move from MySQL to MySQLi but am having some problems.
I am trying to place a series of sprites on a layer, but since
Im trying to move the scroll of a div with jquery, but i dont
I am trying to move a rectangle that i created to the center of
So i'm trying to move multiple sprites on the screen at the same time.
im trying to get a sprite to move around the screen with a walk
At the moment, I have a sprite that I have arbitrarily set to move
I have two sprites, one tracks and follows the other. I already have that

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.