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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:21:21+00:00 2026-06-18T16:21:21+00:00

We have created a grid on texture by directly dividing the texture using gridsize.

  • 0

We have created a grid on texture by directly dividing the texture using gridsize.
We have divided the texture into 10×10. The goal is to modify the texture image using finger.
We are facing issues on the non-retina as well as Retina device when we move say
in the center of the device, some point on left bottom also gets moved. Not sure why this happens.

- (id)init 
{
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) 
    {    
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0     swallowsTouches:YES];
        [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

        if ([CocosDistort isRetinaDisplay]) 
            originalImage = [UIImage imageNamed:@"IMG_1968-hd.PNG"];

        else
            originalImage = [UIImage imageNamed:@"IMG_1968.PNG"];

        texture2D = [[CCTexture2D alloc] initWithImage:originalImage];

        [self body_init];
        self.isTouchEnabled = YES;
    }
    return self;
}

- (void)draw 
{
    glDisableClientState(GL_COLOR_ARRAY);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4ub(224,224,244,200);

    [self body_redraw];

    glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
    glEnableClientState(GL_COLOR_ARRAY);
}

- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event 
{
    isFirstTouch=YES;
    CGPoint location = [self convertTouchToNodeSpace: touch];

    if ([CocosDistort isRetinaDisplay]) 
    {
        mousex = (location.x * 2);
        mousey = (location.y * 2);
    }
    else
    {
        mousex = location.x ;
        mousey = location.y ;
    }

    firstPoint=location;
    grab = [self body_grab:mousex:mousey];
    return YES;
}

- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event 
{
    isFirstTouch=NO;
    CGPoint location = [self convertTouchToNodeSpace: touch];

    mousex1 = 0.0;
    mousey1 = 0.0;

    if ([CocosDistort isRetinaDisplay]) 
    {
        mousex1 =  (location.x * 2) - mousex;
        mousey1 =  (location.y * 2)  - mousey ;
    }
    else
    {
        mousex1 =  location.x  - mousex;
        mousey1 =  location.y  - mousey ;
    }

    if ([CocosDistort isRetinaDisplay]) 
    {
        mousex = (location.x * 2);
        mousey = (location.y * 2);
    }
    else
    {
        mousex = location.x ;
        mousey = location.y ;
    }
    [self body_dynamics:mousex:mousey];
}

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event 
{
    grab = -1;
}

- (void)body_dynamics:(int)x:(int)y 
{
    if (mass[grab].x[0] > x && mass[grab].x[1] > y) 
    {
        grab2 = grab - GRID_SIZE_X;
        grab3 = grab2 - 1;
        grab4 = grab  - 1;
    }
    if (mass[grab].x[0] > x && mass[grab].x[1] < y) 
    {
        grab2 = grab - GRID_SIZE_X;
        grab3 = grab2 + 1;
        grab4 = grab  + 1;
    }
    if (mass[grab].x[0] < x && mass[grab].x[1] < y) 
    {
        grab2 = grab + GRID_SIZE_X;
        grab3 = grab2 + 1;
        grab4 = grab  + 1;
    }
    if (mass[grab].x[0] < x && mass[grab].x[0] > y) 
    {
        grab2 = grab + GRID_SIZE_X;
        grab3 = grab2 - 1;
        grab4 = grab  - 1;
    }
    if (grab != -1 && !mass[grab].nail &&!isFirstTouch)
    {
        mass[grab].x[0]  =  mass[grab].x[0] + mousex1;
        mass[grab].x[1]  =  mass[grab].x[1] + mousey1;
        mass[grab].x[2]  = -(CLIP_FAR - CLIP_NEAR)/4.0;

        mass[grab2].x[0] =  mass[grab2].x[0] + mousex1;
        mass[grab2].x[1] =  mass[grab2].x[1] + mousey1;
        mass[grab2].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;

        mass[grab3].x[0] =  mass[grab3].x[0] + mousex1;
        mass[grab3].x[1] =  mass[grab3].x[1] + mousey1;
        mass[grab3].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;

        mass[grab4].x[0] =  mass[grab4].x[0] + mousex1;
        mass[grab4].x[1] =  mass[grab4].x[1] + mousey1;
        mass[grab4].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;
    }
}

- (int)body_grab:(int)x:(int)y 
{
    float dx[2];
    float d;
    float min_d;
    float min_i;
    int i;

    for (i = 0; i < GRID_SIZE_X*GRID_SIZE_Y; i++)
    {
        dx[0] = mass[i].x[0] - x;
        dx[1] = mass[i].x[1] - y;
        d = sqrt(dx[0]*dx[0] + dx[1]*dx[1]);
        if (i == 0 || d < min_d)
        {
            min_i = i;
            min_d = d;
        }
    }
        return min_i;
}

- (void)body_redraw 
{
    int k;
    int i, j;
    if(mass == NULL) 
        return;

    glBindTexture(GL_TEXTURE_2D, [texture2D name]);

    k = 0;
    for (i = 0; i < GRID_SIZE_X - 1; i++)
    {
        for (j = 0; j < GRID_SIZE_Y - 1; j++)
        {
            GLfloat vertices[]= {
                mass[k].x[0],mass[k].x[1],mass[k].x[2],
                mass[k + 1].x[0],mass[k + 1].x[1],mass[k + 1].x[2],
                mass[k + GRID_SIZE_Y + 1].x[0],mass[k + GRID_SIZE_Y + 1].x[1],
       mass[k + GRID_SIZE_Y + 1].x[2],
                mass[k + GRID_SIZE_Y].x[0],mass[k + GRID_SIZE_Y].x[1],mass[k + GRID_SIZE_Y].x[2]
            };
            GLfloat tex[]={
                mass[k].t[0], mass[k].t[1],
                mass[k + 1].t[0], mass[k + 1].t[1],
                mass[k + GRID_SIZE_Y + 1].t[0], mass[k + GRID_SIZE_Y + 1].t[1],
                mass[k + GRID_SIZE_Y].t[0], mass[k + GRID_SIZE_Y].t[1]
            };

            glVertexPointer(3, GL_FLOAT, 0, vertices);
            glTexCoordPointer(2, GL_FLOAT, 0, tex);
            glDrawArrays(GL_LINE_STRIP, 0,4);

            k++;
         }
         k++;
    }
}

- (void)body_init 
{
    GLint width = texture2D.contentSizeInPixels.width;
    GLint height = texture2D.contentSizeInPixels.height;
    int i, j, k;

    if (mass == NULL)
    {
        mass = (MASS *) malloc(sizeof(MASS)*GRID_SIZE_X*GRID_SIZE_Y);
        if (mass == NULL)
        {
            fprintf(stderr, "body: Can't allocate memory.\n");
            exit(-1);
        }
    }

    k = 0;
    for (i = 0; i < GRID_SIZE_X; i++)
        for (j = 0; j < GRID_SIZE_Y; j++)
        {
            mass[k].nail = (i == 0 || j == 0 || i == GRID_SIZE_X - 1
                            || j == GRID_SIZE_Y - 1);//value is 0/1

            mass[k].x[0] = i/(GRID_SIZE_X - 1.0)*width;
            NSLog(@"mass[%d].x[0]:: %f",k,mass[k].x[0]);

            mass[k].x[1] = j/(GRID_SIZE_Y - 1.0)*height;
            NSLog(@"mass[%d].x[1]:: %f",k,mass[k].x[1]);

            mass[k].x[2] = -(CLIP_FAR - CLIP_NEAR)/4.0;
            NSLog(@"mass[%d].x[2]:: %f",k,mass[k].x[2]);

            mass[k].v[0] = 0.0;
            mass[k].v[1] = 0.0;
            mass[k].v[2] = 0.0;

            mass[k].t[0] = i/(GRID_SIZE_X - 1.0);
            mass[k].t[1] = j/(GRID_SIZE_Y - 1.0);

            k++;
        }
    }
}
  • 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-18T16:21:22+00:00Added an answer on June 18, 2026 at 4:21 pm

    I have solved this issue by modifying my touches moved method:

    - (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event 
    {
        isFirstTouch=NO;
        CGPoint location = [self convertTouchToNodeSpace: touch];//[touch locationInView:touch.view];//
    
        int gridSizeX2 = 20;
    
        if ((location.x < firstPoint.x + gridSizeX2 && location.y < firstPoint.y + gridSizeX2)
        && (location.x > firstPoint.x - gridSizeX2 && location.y > firstPoint.y - gridSizeX2))
       {
            mousex1 = 0.0;
            mousey1 = 0.0;
    
            if ([CocosDistort isRetinaDisplay]) 
            {
                mousex1 =  (location.x * 2) - mousex;
                mousey1 =  (location.y * 2)  - mousey ;
                mousex = (location.x * 2);
                mousey = (location.y * 2);
            }
            else
            {
                mousex1 =  location.x  - mousex;
                mousey1 =  location.y  - mousey ;
                mousex = location.x ;
                mousey = location.y ;
            }
            mousex1 = mousex1 > 0 ? 1:-1;
            mousey1 = mousey1 > 0 ? 1:-1;
    
            [self body_dynamics:mousex:mousey];
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a grid that contains 10x10 buttons using 2d arrays. i tried
Hi friends, Am newbie for windows Development .i have created Grid With tabcontrol using
I have created a grid function using list control. There are two columns in
I have created one editor grid panel using extjs in that grid panel by
I have a grid created using a sql datasource in my asp page. So
Using EXTJS4, I have created a custom grid. I would like one column to
I am using Ext GWT. I have created a Grid with a CheckColumnConfig with
I have created a custom grid module MySQLGrid using Web Application Project, assembly file
I have just created a grid application using the template provided in Visual Studio
I have created a grid in a doGet() function. This grid contains a dynamic

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.