Wednesday, December 9, 2009

Drag and Drop

For Caroline's Cat Game I need to be able to implement some basic drag and drop actions. The game is a basic dress-up. So, to take things, like a bow (UIImageView *bow) off of the cat, I need to drag them over to the icon of the dresser (UIImageView *dresser) and drop them in.

if (CGRectContainsPoint(dresser.frame,[touch locationInView:self.view])) {

bow.image = nil;


I have this code in my touchesEnded event. The CGRectContainsPoint takes two arguments. The first is a rectangle and the second is a CGPoint. If the CGPoint is in the rectangle then it returns true. When the statement returns true, I make the image invisible by setting it to nil. Instead of using the location of my finger, I could use which is also a CGPoint describing the middle of the bow image.

No comments:

Post a Comment