-1
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ is your mainsprite a sprite. \$\endgroup\$ Commented Feb 2, 2012 at 5:13
  • \$\begingroup\$ Woeful lack of research here. \$\endgroup\$ Commented Apr 18, 2012 at 20:45

1 Answer 1

2
\$\begingroup\$

Why not hitBox.center=mainSprite.center ?

[edit]

hitBox.center= CGPointMake(mainSprite.center.x,mainSprite.center.y+5); 
\$\endgroup\$
2
  • \$\begingroup\$ No i mean like 5 pixels above it. Not over it. could i do hitBox.center = mainSprite.center+5 \$\endgroup\$ Commented Jan 29, 2012 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\$ Commented Jan 29, 2012 at 21:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.