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 06-03-2010, 09:42 PM   #1 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default Simple Game, Simple Animations - How to do?

Hi everyone,

I had an idea for a very simple little game I'd like to make. I have never made anything close to a game before so I am really, really new to this. For this game, I'd need to move around some PNG files on the screen - very basic animations.

I put together this code real quick:

Code:
// Jump up
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration: 1.0];

player.frame = CGRectMake(kStartPositionX, (kStartPositionY - 100), player.image.size.width, player.image.size.height);
	
[UIView commitAnimations];
	
// Fall down
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.0];
	
player.frame = CGRectMake(kStartPositionX, kStartPositionY, player.image.size.width, player.image.size.height);
	
[UIView commitAnimations];
"player" is an UIImageView. This does in fact move "player". Not quite the way I want it to but I guess I could get there. (Player jumps up 100 pixel in no time and then slides back down in the course of a second... I don't understand why he "jumps" up... but anyway...)

So, the question I have is: Which is the best approach to make around a couple of objects/images on the screen, detect whether they hit each other etc.... simple stuff. Do these UIView animations work for that kind of stuff?

If not, what do you recommend? What would I have to learn? (Because that's what I want, learn how to do it... it's just that I want to learn the right thing. )

Thanks for your time and any advise is appreciated.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 06-03-2010, 10:44 PM   #2 (permalink)
Indie Dev
 
hm50's Avatar
 
Join Date: May 2009
Location: South Bend, Indiana
Posts: 162
hm50 is on a distinguished road
Smile

If you are considering a game with collisions and or multiple animations and some physics, I would suggest using "cocos2d for iphone" it costs you nothing, and is a quick learn with another great community for support like this one. The latest release 0.99.3 includes many,many examples which you can modify to your hearts desire. Check it out cocos2d for iPhone I think you'll find it very useful!

Good Luck!

You can also find several helpful youtube video tutorials for cocos2d.

My app "Spell Blocks" is made with cocos2d.
__________________
iPhone 3G

Support Indie Devs!! (that goes for newbs too!)

Apps:
Spell Blocks
See Read Say
iStatus
myVIP
myMVP
hm50 is offline   Reply With Quote
Old 06-04-2010, 12:55 AM   #3 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Hey Robert.

For animations of UIImageViews that needs action (ie to check for collisions etc), you are better to use NSTimer, instead of using CAnimation.

CAnimation is good for something not requiring action, like the clouds moving around, etc..

The thing with CAnimation is that, the object is translated immediately once you call the translation, but the OS "plays" the transition later. So when you do animation of translating an object from 0 to 50, the object is already at 50 when it is executed. Only the OS plays it for you. Whilst if u are using NSTimer, the object is translated by x amount each time the code is called.

In my first game, I use CAnimation only as it is just a mancala game that requires no action of objects (but just to animate). In my 2nd game (in progress now), i use a mixture of CAnimation and NSTimer, because I have stuffs all over the places and need to check for collision.

And no, i don't use cocos2d. just xcode.
rocotilos is offline   Reply With Quote
Old 06-04-2010, 11:07 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 651
kapps11 is on a distinguished road
Default

Hey Robert. I think that for most games UIView animations are not usually the best way to go, but for some simple gaes (usually puzzle games) it can work. But cocos2d is a great alternative
But anyway the reason why it "jumps" is just what roco guy (sorry i forgot ur name haha) said. The propert is changed immediately, but the system manages the animation. So when you start another animation immediately after the first one, it finishes that one so that it can start the next one. You could use NSTimers to achieve the animation, but i think using UIView's animation callback methods is a better bet. So when you start the animation, you have to give it a name. Ex: [UIView beginAnimations:@"Animation1" context:nil];
then set the delegate to ur app and then add the function you want to call. So the code would look something like this:
Code:
[UIView beginAnimations:@"MyID" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(methodName:finished:context:)];
- (void)methodName:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context
{
if ([animationID isEqualToString:@”MyID”] && [finished boolValue]) {
[UIView beginAnimations:@”NextStepInMultiStep” context:(void *)];
// do another animation, might use the context in here
[UIView commitAnimations];
}
}
PS: thx to CS193P for the example code, I was too lazy to write it myself
Anyway you could do that and then check the animationID to know which animation ended and then start the one that needs to start after that
kapps11 is offline   Reply With Quote
Old 06-04-2010, 11:28 AM   #5 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Thanks rocotilos and kapps11 for the info on CAnimations. I did use setAnimationDidStopSelector to make it do what I wanted it to do.

Thanks hm50 for pointing out cocos2d. I already expected that CAnimations are not the way to go. As soon as I have more time next week, I'll dive into cocos2d.

Thanks guys, your information was very helpful.


Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson 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: 406
10 members and 396 guests
7twenty7, ChrisYates, djohnson, Duncan C, gmarro, Kirkout, Retouchable, 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:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0