Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-19-2011, 12:18 AM   #1 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 1
skatesnow73 is on a distinguished road
Default 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)
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!

Last edited by skatesnow73; 05-19-2011 at 12:33 AM.
skatesnow73 is offline   Reply With Quote
Reply

Bookmarks

Tags
app, array, drawing, iphone, iphone & ipad game

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 359
7 members and 352 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, PlutoPrime, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0