Cocossharp CCFollow how to offset

yeshiazevyeshiazev Member ✭✭

I have a cocossharp android app, where is follow my player sprite with the layer. It works, but my player is always centered in the screen, and I would like the player at the bottom of the screen, with the layer following it there. I believe cocos2d has an offset parameter, but I do not see that in the Cocossharp implementation. Any ideas how to achieve this? Thanks


  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Hi, @yeshiazev You can show some code or image , this will be helful .

  • yeshiazevyeshiazev Member ✭✭

    Here is the code I'm using to have the Layer follow the player sprite, the code is within the GameLayer class

    PlayerSprite = GetPlayerSprite();
    CCRect rec = new CCRect(0, 0, ContentSize.Width * 100, ContentSize.Height * 100);
    CCFollow fol = new CCFollow(PlayerSprite, rec);

    It works, only issue is, my player sprite is placed in the center of the screen. I'm hoping to have it at the bottom and stay there. It seems like this is possible in cocos2d, wondering if I can also do this in Cocossharp, thanks

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Okey , @yeshiazev does PlayerSprite inherit from CCSprite . And checking it whether has PositionX or PositionYproperty to set .

    Here is a document about CocosSharp for refer.

  • yeshiazevyeshiazev Member ✭✭

    When I put the Follow Action on the layer to follow the PlayerSprite, it puts the Sprite in the middle, and Changing PosX or PosY has no effect. It wants to keep the Sprite in the center, which I get, because it is supposed to follow it. But I am wondering if there is a Y axis offset, so that the Sprite is still centered on the X axis, but lower down on the Y axis. I believe Cocos2d has an offset action, but I can't figure it out with Cocossharp. Thanks

Sign In or Register to comment.