Detecting touch of a sprite for i-phone development
Im pretty new to i-phone development and I am trying to program a basic bubble popper. I have been able to program a game that creates a 10X10 grid using an NSMutableArray and allows you to touch and object and "pop" it. When I went to use a sprite atlas instead of just a UIImage (animated graphics are much more exciting) it changed the the y coordinate of 0 to the bottom left side of the screen when before I believe 0,0 started at the top left side of the screen. So now my touch will have the y inverted so when I touch the 0,0 element it will activate the 0,9 element and my 0,1 will activate the 0,8 element and so on. I have been searching for a while to find out what I might be doing wrong or if there is a beter solution to programing a touch detecting function for what seems to be a simple enough game. 开发者_开发知识库Any Ideas?
two things:
- please provide source code because it makes you issue easier to understand
- have you look at game programming libraries (http://cocos2d.org/ for example) ?
Assuming you are handling the touch from within CCLayer
's ccTouchesBegan:withEvent:
method:
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [self convertTouchToNodeSpace:touch];
// now the location CGPoint variable contain coordinate of the touch aligned to the cocos2d coordinate system
[self popBubbleAtLocation:location];
}
精彩评论