A search through the forum yielded an earlier post from you to detect if an object was above another object. I have adapted it, and it works for the blocks in my blockArray. I cannot get it, however, to work with my stoppedBlocks array at the same time. Here is it at the moment:
Code:
for (UIImageView *block in blockArray) {
for (UIImageView *block in stoppedBlocks) {
float charBottom = (character.frame.origin.y + character.frame.size.height);
float blockTop = block.frame.origin.y;
float heightAboveBlock = blockTop - charBottom;
bool onTop = heightAboveBlock <10 //char is a little above the top of the box
&& heightAboveBlock >-10 //or a little below the top of the box
&& character.center.x > block.frame.origin.x //x is greater than left side
&& character.center.x < block.frame.origin.x + block.frame.size.width; //x is less than right side
if (onTop){
character.frame = CGRectMake(character.frame.origin.x, blockTop-character.frame.size.height,
character.frame.size.width, character.frame.size.height);
ySpeed +=0;
} } }
How do I get it to work for both arrays?
(I have given up with the notion of hitting blocks from the sides and bottom for two reasons: 1) it would make the game incredibly hard to play 2) it would have been quite difficult to achieve :P)
Thanks
Cam