How to add touch event to sprite

NinineaNininea USUniversity ✭✭✭

Is it possible to add touch event to sprite to cocosSharp?

In main layout I have several sprites and need to add touch event for each of them .

Posts

  • NinineaNininea USUniversity ✭✭✭

    I have found out CCTouch and added it to sprite action

  • NinineaNininea USUniversity ✭✭✭

    but it isn't steel clear how to handle moving event?

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Hello Nininea

    Have you seen the Introduction to Game Development with CocosSharp

    Here is the part about Moving the paddle with touch input

  • NinineaNininea USUniversity ✭✭✭

    @kjpou1 thanks for answer . yeah I have seen , but here is defined move only one object - paddleSprite during touch, I need to detect which object (sprite) is touched and move this particular one .

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Not sure exactly but maybe this will help you out. This of course would go inside your touch handler.

                if (sprite1.BoundingBoxTransformedToWorld.ContainsPoint(touches[0].Location))
                    // sprite 1 is hit
                else if (sprite2.BoundingBoxTransformedToWorld.ContainsPoint(touches[0].Location))
                    // sprite 2 is hit
    
  • NinineaNininea USUniversity ✭✭✭

    @kjpou1 this exactly helped me . thanks :)

  • DevanginiDubeyDevanginiDubey USMember ✭✭
    edited April 11

    How to get multiple touch points on each layer? as this BoundingBoxTO parent or world method doesn't work for the multiple ccsprite touch at same time and gives touch of the first touch done on layer always

Sign In or Register to comment.