I have a UIImageView called hitBox, and another image called mainSprite. So what I want to do is when an IBAction is pressed, it will move hitBox to above mainSprite. I don't know if this is syntax but this is what I know moves things on the screen.

hitBox.center = CGPointMake(x coordinate, y coordinate);

I just want to replace x coordinate and y coordinate with something that will place it somewhere in relation mainSprite.

  • \$\begingroup\$ is your mainsprite a sprite. \$\endgroup\$ – Robin Feb 2 '12 at 5:13
  • \$\begingroup\$ Woeful lack of research here. \$\endgroup\$ – MichaelHouse Apr 18 '12 at 20:45

Why not hitBox.center=mainSprite.center ?


hitBox.center= CGPointMake(mainSprite.center.x,mainSprite.center.y+5);
| improve this answer | |
  • \$\begingroup\$ No i mean like 5 pixels above it. Not over it. could i do hitBox.center = mainSprite.center+5 \$\endgroup\$ – Will Jan 29 '12 at 13:50
  • \$\begingroup\$ You can't add 5 to a CGPoint, I've edited my answer to show you how you do this. \$\endgroup\$ – jptsetung Jan 29 '12 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.