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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:31:19+00:00 2026-05-24T20:31:19+00:00

Using this code (tweaked a little) i can’t get a constant Y value. it

  • 0

Using this code (tweaked a little) i can’t get a constant Y value. it keeps changing. X works perfect but Y is really skewed.

Im making tiles about the size of a screen. and when i grab and drag it works fine for x. so if i click a space on screen, say

Touches Ended x : 459.000000 y : 705.000000

and then drag a bit away i get this

Touches Ended x : 459.000000 y : 823.000000

So the x value stay’s which is what i want, but the Y value changes not presenting the proper value

My code for printing out looks like this

NSArray *touchArray = [touches allObjects];        
UITouch * fingerOne = [touchArray objectAtIndex:0];    
CGPoint newTouchLocation = [fingerOne locationInView:[fingerOne view]];
CGPoint mapLoc = [self convertToNodeSpace: newTouchLocation];
NSLog(@"Touches Ended x : %f y : %f", mapLoc.x, mapLoc.y);

and the majority comes from this website…

http://firsttimecocos2d.blogspot.com/2011/07/how-to-scroll-and-zoom-inout-of-map.html

    - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//finds the difference in the original map and the scaled map
int differenceX = mapWidth - (mapWidth*mapScale);
int differenceY = mapHeight - (mapHeight*mapScale);    

// This method is passed an NSSet of touches called (of course) "touches"
// "allObjects" returns an NSArray of all the objects in the set
NSArray *touchArray = [touches allObjects];
//Remove Multi Touch
if ([touchArray count] ==1){

    UITouch * fingerOne = [touchArray objectAtIndex:0];

    CGPoint newTouchLocation = [fingerOne locationInView:[fingerOne view]];
    newTouchLocation = [[CCDirector sharedDirector] convertToGL:newTouchLocation];

    CGPoint oldTouchLocation = [fingerOne previousLocationInView:fingerOne.view];
    oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];

    //get the difference in the finger touches when the player was dragging
    CGPoint difference = ccpSub(newTouchLocation, oldTouchLocation);

    //adds this on to the layers current position, effectively moving it
    CGPoint newPosition = ccpAdd(mapLayer.position, difference);

    CGPoint bottomLeft = newPosition;

    //check to see if the map edges of the map are showing in the screen, if so bringing them back on the view so no black space can be seen
    if (bottomLeft.x - differenceX/2 > 0 - (mapWidth * (1-mapScale)) + (1-mapScale)*33) {
        bottomLeft.x = differenceX/2- (mapWidth * (1-mapScale))+(1-mapScale)*33;
    }

    if (bottomLeft.y - differenceY/2 > 0 -(mapHeight * (1-mapScale))) {
        bottomLeft.y = differenceY/2-(mapHeight * (1-mapScale));

    }

    if (bottomLeft.x + mapWidth*mapScale +differenceX/2 < 440+ (1-mapScale)*33) {
        bottomLeft.x = -differenceX/2 - mapWidth*mapScale + 440 + (1-mapScale)*33;

    }
    if (bottomLeft.y + mapHeight*mapScale +differenceY/2 < 320) {
        bottomLeft.y =  -differenceY/2 - mapHeight*mapScale + 320;

    }

    mapLayer.position = bottomLeft;
  }
}

Anything? 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-05-24T20:31:20+00:00Added an answer on May 24, 2026 at 8:31 pm

    The UIView fingerOne uses might have changed as you moved your finger, which might skew the CGPoint.

    Try this:

    CCDirector* director = [CCDirector sharedDirector];
    CGPoint newTouchLocation = [fingerOne locationInView:[director openGLView]];
    

    100% of the time, the openGLView doesn’t move or change unless you have specifically done so.

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

Sidebar

Related Questions

Using this code to zip a folder and it works perfect on small files
Consider this code: using Microsoft.Office.Interop.Word; ApplicationClass _application = new ApplicationClass(); Can I get the
Using this code, I can get a very cheesy red lettered message. <form id=frmValidator
I'm using this code, and I get the stack trace that is listed below.
I am using this code to get the background image of a div .
Using this code, many keys are output, but I expected no output: import os
I using this code for sum selected cells. Its work good but when user
In using this code (adapted from here ) I get the following error: The
Using this code, I can send emails to people. However, every time I press
Using this code I cannot get a file to upload correctly to the website.

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.