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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:34:48+00:00 2026-05-20T11:34:48+00:00

I have different tile layers that I move at different speeds, my player is

  • 0

I have different tile layers that I move at different speeds, my player is fixed in place(horizontally). Now how do I detect that my player is colliding width a tile? How do I know the coordinates of the tiles in the different layers?

  • 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-20T11:34:49+00:00Added an answer on May 20, 2026 at 11:34 am

    I figured this out with the help of this tutorial http://paulsonapps.wordpress.com/2010/03/12/tutorial-1-tilemap-with-collision-game-cocos2d/

    -(void)handleCollision
    {
        for (CCTMXLayer *lr in layers) {
            // Determine the four corners of my player
            int tlXright = floor(player.playerSprite.position.x+player.playerSprite.contentSize.width-lr.position.x);
            int tlXleft = floor(player.playerSprite.position.x-lr.position.x);
            int tlYup = floor(player.playerSprite.position.y+player.playerSprite.contentSize.height);
            int tlYdown = floor(player.playerSprite.position.y);
    
    
            //Convert our Map points 
            CGPoint nodeSpace1 = [tileMap convertToNodeSpace:ccp(tlXright,tlYdown)];
            pos1X = floor(nodeSpace1.x / tileMap.tileSize.width);
            pos1Y = floor(tileMap.mapSize.height - (nodeSpace1.y / tileMap.tileSize.height));
    
            CGPoint nodeSpace2 = [tileMap convertToNodeSpace:ccp(tlXright,tlYup)];
            pos2X = floor(nodeSpace2.x / tileMap.tileSize.width);
            pos2Y = floor(tileMap.mapSize.height - (nodeSpace2.y / tileMap.tileSize.height));
    
            CGPoint nodeSpace3 = [tileMap convertToNodeSpace:ccp(tlXleft,tlYdown)];
            pos3X = floor(nodeSpace3.x / tileMap.tileSize.width);
            pos3Y = floor(tileMap.mapSize.height - (nodeSpace3.y / tileMap.tileSize.height));
    
            CGPoint nodeSpace4 = [tileMap convertToNodeSpace:ccp(tlXleft,tlYup)];
            pos4X = floor(nodeSpace4.x / tileMap.tileSize.width);
            pos4Y = floor(tileMap.mapSize.height - (nodeSpace4.y / tileMap.tileSize.height));
    
    
            unsigned int gid5 = [lr tileGIDAt:ccp(pos1X,pos1Y)];
            unsigned int gid6 = [lr tileGIDAt:ccp(pos2X,pos2Y)];
            unsigned int gid7 = [lr tileGIDAt:ccp(pos3X,pos3Y)];
            unsigned int gid8 = [lr tileGIDAt:ccp(pos4X,pos4Y)];
    
    
            //NSLog(@"gid5:%d gid6:%d gid7:%d gid8:%d",gid5,gid6,gid7,gid8);
            / NSLog(@"pos1x:%d pos1y:%d pos4x:%d pos4y:%d",pos1X ,pos1Y,pos4X,pos4Y);
            if (gid5 == 5) {
                [lr removeTileAt:ccp(pos1X,pos1Y)];
            }
    
    
            if (gid6 == 5) {
                [lr removeTileAt:ccp(pos2X,pos2Y)];
    
            }
    
            if (gid7 == 5) {
                [lr removeTileAt:ccp(pos3X,pos3Y)];
            }
    
            if (gid8 == 5) {
                [lr removeTileAt:ccp(pos4X,pos4Y)];
            }
        }
    }   
    

    to know the coordinate of the tile, i subtracted the layer position to the position of the player

     
    int tlXright = floor(player.playerSprite.position.x+player.playerSprite.contentSize.width-lr.position.x);
     

    and converted it like in the tutorial.

    CGPoint nodeSpace1 = [tileMap convertToNodeSpace:ccp(tlXright,tlYdown)];
        pos1X = floor(nodeSpace1.x / tileMap.tileSize.width);
        pos1Y = floor(tileMap.mapSize.height - (nodeSpace1.y / tileMap.tileSize.height));

    …

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

Sidebar

Related Questions

I have different urls that points to the same code www.url1.com www.url2.com I need
I have noticed over the years that different developers have different criteria for what
I have two functions that have different enough logic but pretty much the same
I have different php output in jQuery-based tabs. This output is formed from database
I have different projects written in .NET 3.5 and some unit test projects to
different programming languages have different features or lack certain features. Design patterns are a
Do different browsers (Firefox/Safari/IE/Opera) have different limits on the length of the name attribute
You can have different naming convention for class members, static objects, global objects, and
Windows Mobile devices have different behaviour for suspending when the device is on battery
On a page I have different element which I bound yo different Ajax calls.

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.