Get Touch position
The most interesting part is the location of the touch. Next we'll use the touch location to add sprites to the screen position each time the player taps. To do this we need to modify the Touchbegan implementation, replacing the old code as follows:
-(void)Touchbegan:(Uitouch*) Touchwithevent:(uievent*) event{//We want to know the location of our touchinchThis sceneCgpointTouchlocation = [TouchLocationinnode: Self];//Create a' hero 'SpriteCcsprite*hero = [Ccsprite spritewithimagenamed:@"Hero.png"]; [ Self AddChild:Hero];//Place the sprite on the touch location hero.position = touchlocation;}
The implementation is fairly straightforward. The most interesting part is the location of the actual touch. The Locationinnode method converts the OpenGL view coordinates of the touch to the coordinates within node that are passed as a parameter to the method. (In this case, because we need to know where the screen touch actually is in mainscene).
Once we have reached the touch position, we simply create a new ccsprite node and add it to the Mainscene. where the "hero.png" Picture resource is part of the starter project that you downloaded from the beginning.
Once you run the project, you should be able to place Mgwu heroes full screen.
Now that you're familiar with the basics, we'll look further at the touch life cycle and how you can create complex touch processing in your game.
Touch Handling in Cocos2d 3.x (TRI)