Forum Libraries, Components, and Plugins

Please help with tile map scrolling CCFollow

I have 320 x 640 test tile map which I only want half the area of (160 x 320) visible on screen at a time and let the rest scroll into view when the player moves accordingly. I have the following relevant lines of code:

CCScene.SetDefaultDesignResolution (160.0f, 320.0f, CCSceneResolutionPolicy.ShowAll);
RunAction(new CCFollow(sprite, new CCRect(0, 0, 320.0f, 640.0f)));

This does scroll the map but the scrolled in content is blank (black screen). Please can someone help me understand how to go about doing this the right way with code example?


  • RamiTabbaraRamiTabbara AUMember, Xamarin Team Xamurai

    Hi Hashen,

    Please make sure you're applying the RunAction to the CCTileMap:TileLayersContainer node property. i.e.

    tileMap.TileLayersContainer.RunAction(new CCFollow(sprite, new CCRect(0, 0, 320.0f, 640.0f)));

    You can find more information on our changes to our tile-map support here. Let me know if that sorts out the issue.

  • DevHashDevHash ZAMember

    Thanks Rami you are a star! That sorted it. Greatly appreciate this API port.

  • How would you implement a CCFollow to scroll the whole map? The approach I was using was to change the TileLayersContainer.Position so as to move the map around the player sprite; this approach is alot cleaner (and also allows me to move the sprite itself instead, so the screen gradually scrolls instead of jumping around by huge increments). But if I use the width and height of my SetDesignResolution, or the size of the window itself, it doesn't scroll enough to allow my sprite to reach the edge of the map. Moving the map around him does, but it gives me choppy movement since there's no time for him to 'walk' to where the user clicked, the TileLayersContainer.Position is just automatically set to the location of the click in worldspace.
    If I should make a new question for this please let me know, I just thought it was pretty much directly related to this question so it didn't require a new one to be asked.

Sign In or Register to comment.