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 01-22-2012, 09:22 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
noaim is on a distinguished road
Default Code Problem Collision with Frames and loose Live

Hi Guys,

i have a problem with a code,
i want that the variable live is set into -1*if CGRect the ball frame and the snake frame.

My Code:

if (CGRectIntersectsRect(ball.frame, snake.frame)) {
if (ball.center.y + 10 > snake.center.y) {
if (ballVelocity.y < 0) {
snakeVeloctiy.y = .1;
live = live -1;
}
}
}

But then i lost live a few times for each collision in this few sec. i only want that itīs loose it for one time.

I hope you understand my Problem
So Thanks for every Help!

Greetings Andreas
noaim is offline   Reply With Quote
Old 01-22-2012, 12:23 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
noaim is on a distinguished road
Default

Canīt anybody help me?
noaim is offline   Reply With Quote
Old 01-23-2012, 02:36 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 12
Zanzibar7 is on a distinguished road
Default

Quote:
Originally Posted by noaim View Post
Hi Guys,

i have a problem with a code,
i want that the variable live is set into -1*if CGRect the ball frame and the snake frame.

My Code:

if (CGRectIntersectsRect(ball.frame, snake.frame)) {
if (ball.center.y + 10 > snake.center.y) {
if (ballVelocity.y < 0) {
snakeVeloctiy.y = .1;
live = live -1;
}
}
}

But then i lost live a few times for each collision in this few sec. i only want that itīs loose it for one time.

I hope you understand my Problem
So Thanks for every Help!

Greetings Andreas
If I understand your question, then one way you could fix it is to create a new integer, set it equal to 0, then add 1 to that instead of live. Then ask if the new integer is equal to 1, and if it is subtract 1 from live. Then when the rectangles stop intersecting, set the new integer back to 0.

It would look something like this:
Code:
//Before your main loop: Integer myInteger = 0;

if (CGRectIntersectsRect(ball.frame, snake.frame)) {
        if (ball.center.y + 10 > snake.center.y) {
            if (ballVelocity.y < 0) {
                snakeVeloctiy.y = .1;
                myInteger++;
                if (myInteger == 1) {
                    live--; // live-- is the same as live = live - 1
                }
            }
        }
    }
else {
    myInteger = 0;
}
I don't know if this is the best solution, but I think it will work.

P.S. It's not a good idea to expect an answer in the first few hours on any forum.
http://www.iphonedevsdk.com/forum/ip...uidelines.html

Last edited by Zanzibar7; 01-23-2012 at 03:15 AM.
Zanzibar7 is offline   Reply With Quote
Old 01-23-2012, 08:42 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 3
noaim is on a distinguished road
Default

Yes, that is what i mean,
thanks a lot, it is working perfect.

In Future i consider your advice,
thanks!

noaim 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: 386
8 members and 378 guests
apatsufas, comicool, dansparrow, husthlj, LunarMoon, mer10, Murphy, pbart
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,677
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, husthlj
Powered by vBadvanced CMPS v3.1.0

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