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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-18-2011, 08:21 PM   #1 (permalink)
Registered Member
 
Psevertson's Avatar
 
Join Date: Jan 2011
Posts: 22
Psevertson is on a distinguished road
Default Emitting UIImageViews

So I am trying to create a game. The most similar one I could find on the app store is Tasty Planet.
So mostly what I have so far is an NSTimer that starts this every 3 seconds:

image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
[self.view addSubview:image1];
image1.frame = CGRectMake(320, (random() % 480), 12, 12);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:8];
image1.transform = CGAffineTransformMakeTranslation (-370, (random() % 480) - 240 ); image1.alpha = 1.0; [UIView commitAnimations];

it randomly emits images from right to left. I also have, image2, which is controlled by tilting.
I want to be able to tell when they cross.
I've tried using:
if (CGRectIntersectsRect(image2.frame, image1.frame)){
image1.hidden = YES;
image2.transform = CGAffineTransformScale(image2.transform, 1.2 , 1.2);
}else {
}

But it wont work.
I think the problem is because the timer creates a whole new image.
Is the a better way to do what I am trying to do so far.
Psevertson is offline   Reply With Quote
Old 02-19-2011, 05:56 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Himeji, Japan
Posts: 9
Shota is on a distinguished road
Default

Using "animation block", the object is looks like moving,
but the frame's value isn't change (frame.center = end animating point)

I think, it may become reason.

so, if you want to catch "intersect", coding without animation block(= [beginAnimation:] to [commitAnimation]).
Shota is offline   Reply With Quote
Old 02-20-2011, 04:29 PM   #3 (permalink)
Registered Member
 
Psevertson's Avatar
 
Join Date: Jan 2011
Posts: 22
Psevertson is on a distinguished road
Default still confused

Quote:
Originally Posted by Shota View Post
Using "animation block", the object is looks like moving,
but the frame's value isn't change (frame.center = end animating point)

I think, it may become reason.

so, if you want to catch "intersect", coding without animation block(= [beginAnimation:] to [commitAnimation]).
So how would I change the code? I dont get where it goes?
Psevertson is offline   Reply With Quote
Old 02-21-2011, 08:06 AM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Himeji, Japan
Posts: 9
Shota is on a distinguished road
Default

Can open this attached file?

I think, you may want to do like this (if it's wrong, so sorry).
Explaining about this way in English, is difficult for me, and code become too long. but did like this, can move obj without animation block.

When intersect, small view is changed background color, rewrite this part.
Use UIView class, rewrite your need class.
Attached Files
File Type: zip Emit.zip (22.3 KB, 6 views)
Shota is offline   Reply With Quote
Old 02-21-2011, 08:05 PM   #5 (permalink)
Registered Member
 
Psevertson's Avatar
 
Join Date: Jan 2011
Posts: 22
Psevertson is on a distinguished road
Default not squares

Quote:
Originally Posted by Shota View Post
Can open this attached file?

I think, you may want to do like this (if it's wrong, so sorry).
Explaining about this way in English, is difficult for me, and code become too long. but did like this, can move obj without animation block.

When intersect, small view is changed background color, rewrite this part.
Use UIView class, rewrite your need class.
Thank you so much for doing all this. Is there anyway to make it be an image, instead of squares?
Thanks!
Psevertson is offline   Reply With Quote
Old 02-21-2011, 10:27 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Himeji, Japan
Posts: 9
Shota is on a distinguished road
Default

sure, UIView's "Ball"class need to rewrite UIImageView class.

<.h part>

@interface Ball : UIImageView

<.m part>

1: "initWithFrame:" method,

- (id)initWithFrameCGRect)rect {

self = [super initWithFrame:rect];

self.image = [UIImage imageNamed:@"yourImage.png"]; (jpg is also OK)

}

>>Add "self.image" in code.


2: for() in "moveObj:"method.

for (UIImageView *obj in self.superview.subviews)

>>UIView rewrite to UIImageView.


*: optionally, if you need,(on initWithFrame

self.contentMode = UIViewContentModeScaleToFill;

Last edited by Shota; 02-21-2011 at 10:32 PM. Reason: obj to *obj (sorry
Shota is offline   Reply With Quote
Old 02-22-2011, 06:32 PM   #7 (permalink)
Registered Member
 
Psevertson's Avatar
 
Join Date: Jan 2011
Posts: 22
Psevertson is on a distinguished road
Default Thanks!

Quote:
Originally Posted by Shota View Post
sure, UIView's "Ball"class need to rewrite UIImageView class.

<.h part>

@interface Ball : UIImageView

<.m part>

1: "initWithFrame:" method,

- (id)initWithFrameCGRect)rect {

self = [super initWithFrame:rect];

self.image = [UIImage imageNamed:@"yourImage.png"]; (jpg is also OK)

}

>>Add "self.image" in code.


2: for() in "moveObj:"method.

for (UIImageView *obj in self.superview.subviews)

>>UIView rewrite to UIImageView.


*: optionally, if you need,(on initWithFrame

self.contentMode = UIViewContentModeScaleToFill;
Once again thanks for doing all this. One last thing. I need to check if it intersects with an image that is in my other view.
I dont know how to do this because it is undeclared.
Psevertson is offline   Reply With Quote
Old 02-23-2011, 05:51 AM   #8 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Himeji, Japan
Posts: 9
Shota is on a distinguished road
Default

OK, sure. I'm glad that I could help you.

if your view is UIImageView class, this loops is not need to change.
But if your view is other class (UILabel, UIButton, UIView...etc), UIImageView should rewrite to UIView (or id).

<Ball.m>

for(UIImageView *obj in self.superview.subview) {
if(CGRectIntersectsRect(self.frame, obj.frame) && !CGRectEqualToRect(self.frame, obj.frame)) {
// Insert code here, Intersection.
}
}

this for() loop means "reference all view".

have to choose view in your way.


for example (write in "insert code here, Intersection")

1:
if(obj.frame.size.x != 12.0) {
// your view's size is not 12.0.
}

2:
if([obj class] != [UIImageView class]) {
// your view's class is not UIImageView. (same mean "isKindofClass:")
}

3:
if(obj.image == [UIImage imageNamed:@"yourImage.png"]) {
// choose by image name.
}

4:
if([obj respondToSelector(methodOfYourClass)]) {
// if the instance can respond your method.
}

you should think which way is better, or other way is more better.
Shota is offline   Reply With Quote
Old 03-18-2011, 03:40 PM   #9 (permalink)
Registered Member
 
Psevertson's Avatar
 
Join Date: Jan 2011
Posts: 22
Psevertson is on a distinguished road
Default More help

Quote:
Originally Posted by Shota View Post
OK, sure. I'm glad that I could help you.

if your view is UIImageView class, this loops is not need to change.
But if your view is other class (UILabel, UIButton, UIView...etc), UIImageView should rewrite to UIView (or id).

<Ball.m>

for(UIImageView *obj in self.superview.subview) {
if(CGRectIntersectsRect(self.frame, obj.frame) && !CGRectEqualToRect(self.frame, obj.frame)) {
// Insert code here, Intersection.
}
}

this for() loop means "reference all view".

have to choose view in your way.


for example (write in "insert code here, Intersection")

1:
if(obj.frame.size.x != 12.0) {
// your view's size is not 12.0.
}

2:
if([obj class] != [UIImageView class]) {
// your view's class is not UIImageView. (same mean "isKindofClass:")
}

3:
if(obj.image == [UIImage imageNamed:@"yourImage.png"]) {
// choose by image name.
}

4:
if([obj respondToSelector(methodOfYourClass)]) {
// if the instance can respond your method.
}

you should think which way is better, or other way is more better.
Ok, I've been working with this. Now I need to change the view after 3 intersections.
I've tried using:
[self.delegate gameViewControllerDidFinish:self];
but every time it ends up crashing. I have no idea why.
Psevertson is offline   Reply With Quote
Old 03-22-2011, 07:09 AM   #10 (permalink)
Registered Member
 
Join Date: Feb 2011
Location: Himeji, Japan
Posts: 9
Shota is on a distinguished road
Default

Quote:
Originally Posted by Psevertson View Post
Ok, I've been working with this. Now I need to change the view after 3 intersections.
I've tried using:
[self.delegate gameViewControllerDidFinish:self];
but every time it ends up crashing. I have no idea why.
...gameViewControllerDidFinish & delegate? No build failed?

Do you get this error message?

"request for member 'delegate' in something not a structure or union"


if you don't get it, check to use these method.

NSLog(@"%@",self.delegate);

if([self.delegate respondsToSelector:@selector(gameViewControllerDid Finish]) {
[self.delegate gameViewControllerDidFinish:self];
}

If your method is valid return YES value, return NO value = no method or no link to call method.

/////////////////////

You should set delegate, before call delegate's method.

1: set delegate.

YourView *obj = [YourView alloc] initWithFrame(rect)];

[obj setDelegate:self]; (viewController: when make instance);

////top of YourView.m class/////////////////////

- (void)setDelegate: (id)_delegate {

delegate = _delegate
//delegate is member variable.
}

- (id)delegate {
return delegate;
}

After you wrote that, delegate is valid.
Shota is offline   Reply With Quote
Reply

Bookmarks

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: 427
9 members and 418 guests
7twenty7, chemistry, ChrisYates, hussain1982, Retouchable, skrew88, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

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