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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:56:56+00:00 2026-05-25T01:56:56+00:00

hi made an object layer on my tile map with tile map editor like

  • 0

hi made an object layer on my tile map with tile map editor like this :

https://i.stack.imgur.com/f5fZK.png

The big square represent my object layer named : ObjectIt.

My problem is when i touch the square in the simulator it doesn’t correspond to the right place. Some people told me problem with float value or open gl but I’m noob i need clear answers .

This is my code :

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

    NSLog(@"touch detect");
    CCNode* node = [self getChildByTag:TileMapNode];
    NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap");
    CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node;
    // Get the position in tile coordinates from the touch location
    CGPoint touchLocation = [self locationFromTouches:touches];
    CGPoint tilePos = [self tilePosFromLocation:touchLocation tileMap:self.tileMap];
    // Check if the touch was on water (e.g., tiles with isWater property)
    bool isTouchOnWater = NO;


    CCTMXObjectGroup* objectLayer = [tileMap objectGroupNamed:@"ObjectIt"];
    bool isTouchInRectangle = NO;
    int numObjects = [objectLayer.objects count];
    for (int i = 0; i < numObjects; i++)
    {

        NSDictionary* properties = [objectLayer.objects objectAtIndex:i];
        CGRect rect = [self getRectFromObjectProperties:properties tileMap:tileMap];
        if (CGRectContainsPoint(rect, touchLocation))
        {
            isTouchInRectangle = YES;
            break; }
    }


    if (isTouchInRectangle)
    {

        NSLog(@"TOUCH IN RECTANGLE");
       // get the ALGORITH FOR TOWERS 
    }

}
-

(CGPoint) locationFromTouch:(UITouch*)touch
{
    CGPoint touchLocation = [touch locationInView: [touch view]];
    return [[CCDirector sharedDirector] convertToGL:touchLocation];
}

-(CGPoint) locationFromTouches:(NSSet*)touches
{
    return [self locationFromTouch:[touches anyObject]];
}

-(CGRect) getRectFromObjectProperties:(NSDictionary*)dict
                              tileMap:(CCTMXTiledMap*)tileMap
{
    float x, y, width, height;
    x = [[dict valueForKey:@"x"] floatValue] + tileMap.position.x;
    y = [[dict valueForKey:@"y"] floatValue] + tileMap.position.y;
    width = [[dict valueForKey:@"width"] floatValue];
    height = [[dict valueForKey:@"height"] floatValue];
    return CGRectMake(x, y, width, height);
}

Thats the code , ill give you more if you need.

Also : when i run on the iPhone i got vertical black lines…

  • 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-25T01:56:56+00:00Added an answer on May 25, 2026 at 1:56 am

    In order to get the correct touch location in Cocos2D points use this CCNode convenience method:

    - (CGPoint)convertTouchToNodeSpace:(UITouch *)touch
    {
        CGPoint point = [touch locationInView: [touch view]];
        point = [[CCDirector sharedDirector] convertToGL: point];
        return [self convertToNodeSpace:point];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've made POCO object mapped to database like this: class MoneyObject { Money MoneyAmmount
Can we use Business Objects which we made & data acess Layer of LINQ?
I made a custom TObjectList descendant designed to hold subclasses of a base object
I have a collection of an object called Bookmarks which is made up of
I'm trying to determine if any changes were made to a particular entity object.
Made this nice little loop for hiding and showing div's, works as a charm
I am new to cocos2d and suddenly got this EXC_BAD_ACCESS, I made a new
I have made this post over a year ago, and I think it makes
I need a little heads up on the mistake I have made on this
made an object, MyTextBoxCreator. i need to make lots of text boxes dynamically. i

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.