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 12-31-2009, 05:56 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
mikelowe is on a distinguished road
Question Subtracting 1 from int

in my game, livesInt is how many lives the user has and lives is the label that displays the int. When two images collide, the livesInt is supposed to -1.

I am having trouble doing this. what i have is:


HTML Code:
if(CGRectIntersectsRect(image1.frame, image2.frame)) {
		image1.center = CGPointMake(160.0, 20);
                //this is where i need help:
		livesInt = livesInt -1;
		lives.text = [NSString stringWithFormat:@"%i", livesInt];
	}
mikelowe is offline   Reply With Quote
Old 12-31-2009, 06:15 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

That looks fine to me, assuming that "livesInt" is declared as an int and not an int pointer (int *). In what way is it not working?
__________________

Free Games!
smasher is offline   Reply With Quote
Old 12-31-2009, 06:26 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
mikelowe is on a distinguished road
Default

It would subtract 4. it works now because it was *livesInt
mikelowe is offline   Reply With Quote
Old 01-01-2010, 01:25 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 471
WillSDev is on a distinguished road
Default

isn't it always better to do int --, rather then int - 1
__________________
01010111 01101111 01110111 00101100 00100000 01001010 01110101 01110011 01110100 01101001 01101100 01101100 00110100 00110101 00101100 00100000 01111001 01101111 01110101 01110010 00100000 01110011 01101111 01101111 01101111 00100000 01100011 01101111 01101111 01101111 01101100
WillSDev is offline   Reply With Quote
Old 01-01-2010, 02:26 AM   #5 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by WillSDev View Post
isn't it always better to do int --, rather then int - 1
I'd be shocked if they compiled down to different assembly on a modern compiler. But livesInt--; would be shorter and it's harder to mistype; you'll never accidentally do x = y-1 when you meant to do x=x-1.
__________________

Free Games!

Last edited by smasher; 01-01-2010 at 02:45 AM.
smasher is offline   Reply With Quote
Old 01-03-2010, 05:25 PM   #6 (permalink)
Beast Iphone Developor
 
justill45's Avatar
 
Join Date: Aug 2009
Location: Atlanta, Georgia
Age: 16
Posts: 1,302
justill45 is on a distinguished road
Default

Quote:
Originally Posted by WillSDev View Post
isn't it always better to do int --, rather then int - 1
int = int - 1, int --, int -= 1. Not much of a difference except the letters themselves
justill45 is offline   Reply With Quote
Reply

Bookmarks

Tags
int, label, lives, subtraction

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: 400
7 members and 393 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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