Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Drawing Images to Screen with code loop - iPhone help

Hey all, I am trying to make a method that draws a block to the screen, moves to the edge with accelerometer input, stops when it hits the edge and stays, and then draws another block (of a random different color and size). I have this code to draw so far which works...

CGRect myImageRect = CGRectMake(135.0f, 215.0f, 50.0f, 50.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"block1.png"]];
myImage.opaque = NO; // explicitly opaque for performance
[self.view addSubview:myImage];
[myImage release];

and then this code:

float newX = myImage.center.x + (accel.x * 12);
float newY = myImage.center.y + (accel.y * -12);
if(newX >= 30 && newY >= 50 && newX <= 290 && newY <= 430)<br /> myImage.center = CGPointMake(newX, newY);

which used to move my block how I wanted with accel input when I wasn't 'drawing' the block 'with code' and I was actually just dragging it into the screen without coding it. So now with the above code that is drawing myImage, it is not working for the accel input for some reason?

So as you can see my first image is called block1.png. Now, I have many different block.png's and they are all different, but right now I am specifying the size and shape. So I either need to make a loop with the above code and somehow get it to randomly change the images, or I need to use an array and load in all of my images and then pull those out one at a time randomly whenever necessary. So my psuedocode for this is:

start of with first image
move
stop
check for win
draw new random image
move
stop
check for win
loop

and this should keep looping until my winning condition. What is the best way I should go about implementing this? Somehow making a loop with my above drawing code (I have tried this and not gotten anything to work) or loading in the images I have in an array and pulling them out randomly? How would I do this? Any help would be appreciated! Thank you!
Sign In or Register to comment.