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 07-07-2010, 03:14 PM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 11
cobroke is on a distinguished road
Default How do I make ball disappear?

I am trying to make the ball disappear when it goes over a hole. I am getting a "method undeclared" error for my makeBallDisappear. Not sure what I am doing wrong.

.h file
#import <UIKit/UIKit.h>
#define BALL_RADIUS 25
#define RHOLE_RADIUS 40
#define BHOLE_RADIUS 40

@interface AccelViewController : UIViewController <UIAccelerometerDelegate>{
IBOutlet UIImageView *ball;
IBOutlet UIImageView *ball2;
IBOutlet UIImageView *redhole;
IBOutlet UIImageView *bluehole;
IBOutlet UIImageView *bkgrnd;
IBOutlet UILabel *score;
IBOutlet UILabel *scoreLabel;

float valueX;
float valueY;
float valueA;
float valueB;

}

-(void)makeBallDisappear;

@end


.m file

#import "AccelViewController.h"
#import "Math.h"
@implementation AccelViewController


-(void)accelerometer: (UIAccelerometer *)accelerometer didAccelerate: (UIAcceleration *)acceleration {
valueX = acceleration.x*40.0;
valueY = acceleration.y*40.0;

int newX = (int)(ball.center.x +valueX);
if (newX > 320-BALL_RADIUS)
newX = 320-BALL_RADIUS;
if (newX< 0+BALL_RADIUS)
newX = 0+ BALL_RADIUS;

int newY = (int)(ball.center.y - valueY);
if (newY > 460-BALL_RADIUS)
newY =460-BALL_RADIUS;
if (newY <0+BALL_RADIUS)
newY = 0+BALL_RADIUS;

CGPoint newCenter = CGPointMake(newX, newY);

ball.center = newCenter;

valueA = acceleration.x*17.0;
valueB = acceleration.y*17.0;

int newA = (int)(ball2.center.x +valueA);
if (newA > 320-BALL_RADIUS)
newA = 320-BALL_RADIUS;
if (newA< 0+BALL_RADIUS)
newA = 0+ BALL_RADIUS;

int newB = (int)(ball2.center.y -valueB);
if (newB > 460-BALL_RADIUS)
newB =460-BALL_RADIUS;
if (newB <0+BALL_RADIUS)
newB = 0+BALL_RADIUS;


CGPoint aNewCenter = CGPointMake(newA, newB);

ball2.center = aNewCenter;

-(void)makeBallDisappear{
{

if fabs(redhole.x-ball.valueX < RHOLE_RADIUS-BALL_RADIUS)
&&
fabs(redhole.y-ball.valueY < BHOLE_RADIUS-BALL_RADIUS)

{

[view ball.visible = NO];
}
}}

Thank you for your help!

-R
cobroke is offline   Reply With Quote
Old 07-07-2010, 03:50 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Looks to me like you're missing an ending '}' at the end of your accelerometer method in the .m
smithdale87 is offline   Reply With Quote
Old 07-07-2010, 04:06 PM   #3 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 11
cobroke is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
Looks to me like you're missing an ending '}' at the end of your accelerometer method in the .m
You are def right that I was missing that bracket. I put it in and still getting errors.

These are my new errors:

1. Expected "(" before 'fabs'
2. Request for member 'x' in something not a structure or union
3. Request for member 'y' in something not a structure or union
4. Request for member 'value' in something not a structure or union
5. Expected ':' before '{' token

is my method written correctly for "makeBallDisappear" ?

is this a sufficient declaration in the .h file or do I need to put in the method parameters?
-(void)makeBallDisappear;


#import "AccelViewController.h"
#import "Math.h"

@implementation AccelViewController


-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
valueX = acceleration.x*40.0;
valueY = acceleration.y*40.0;

int newX = (int)(ball.center.x +valueX);
if (newX > 320-BALL_RADIUS)
newX = 320-BALL_RADIUS;
if (newX< 0+BALL_RADIUS)
newX = 0+ BALL_RADIUS;

int newY = (int)(ball.center.y - valueY);
if (newY > 460-BALL_RADIUS)
newY =460-BALL_RADIUS;
if (newY <0+BALL_RADIUS)
newY = 0+BALL_RADIUS;

CGPoint newCenter = CGPointMake(newX, newY);

ball.center = newCenter;

valueA = acceleration.x*17.0;
valueB = acceleration.y*17.0;

int newA = (int)(ball2.center.x +valueA);
if (newA > 320-BALL_RADIUS)
newA = 320-BALL_RADIUS;
if (newA< 0+BALL_RADIUS)
newA = 0+ BALL_RADIUS;

int newB = (int)(ball2.center.y -valueB);
if (newB > 460-BALL_RADIUS)
newB =460-BALL_RADIUS;
if (newB <0+BALL_RADIUS)
newB = 0+BALL_RADIUS;


CGPoint aNewCenter = CGPointMake(newA, newB);

ball2.center = aNewCenter;
}

-(void)makeBallDisappear
{


if fabs(redhole.x-ball.valueX < RHOLE_RADIUS-BALL_RADIUS)
&&
fabs(redhole.y-ball.valueY < BHOLE_RADIUS-BALL_RADIUS)

{

[view ball.visible = NO];
}
}

Last edited by cobroke; 07-07-2010 at 04:09 PM.
cobroke is offline   Reply With Quote
Old 07-07-2010, 04:11 PM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

This is cluttered with syntactical errors. Really basic stuff...

your "if fabs(redhole...." is missing a set of parentheses. It should be if (fabs...&& ...)

Code:
[view ball.visible = NO];
Remove the "[" and "]"
smithdale87 is offline   Reply With Quote
Old 07-07-2010, 04:19 PM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 11
cobroke is on a distinguished road
Default

sorry I am an advanced newbie!
cobroke is offline   Reply With Quote
Reply

Bookmarks

Tags
accelerometer method 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: 328
8 members and 320 guests
bignoggins, Chickenrig, firecall, iNet, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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