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-19-2011, 12:56 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 83
vogueestylee is on a distinguished road
Default viewdidload - goes only once? first time?

hi, i'm new there so hi all

it seems to be quality forum so i will try, maybe somebody will give me an answer, i'm new to programming and have (maybe stupid) question:

is the viewDidLoad {} function goes only for first time of app start?

because i got code like:
Code:
- (void)viewDidLoad {
	
	UIAccelerometer *accelerometer = [UIAccelerometer    sharedAccelerometer];
	accelerometer.delegate = self;
	accelerometer.updateInterval = 1.0f/30.0f;
	
	
	
	[super viewDidLoad];
	ahax = ahay = 150;
	ahabod = CGPointMake(ahax,ahay);
	
	[NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];

}
so at the befinning i would like to set image x,y coordinates to 150 BUT later in gameloop a want to change position of image, but it don't respond (stay on the 150,150), so, is the gameloop under viewdidload or viewdidload always set 150,150 for each time?

(ahax, ahay are defined in .h file (to have "global" access to him.. if i understand this good..)

and what is that time in NSTimet: 0.033? it is in hours or..?


edit:

Code:
the gameloop looks like

if (accelx.... < 0.1.... for example)
{
ahax += (accelx*5)
}

image.center = ahabod;

...
so image should move...

Last edited by vogueestylee; 02-19-2011 at 01:10 PM.
vogueestylee is offline   Reply With Quote
Old 02-19-2011, 02:25 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

You have two questions and I'll try to hit them both.

>is the viewDidLoad {} function goes only for first time of app start?

No, viewDidLoad get called *if* the view is not already loaded when someone asks for thatController.view. It will always be called at least once when you display the view. If you re-use the viewController then it *may* get called again, but only if the view was unloaded as result of a memory warning.

Your second question - why is image not moving - seems to be because you are not changing the values in ahabod. It looks like you set them once and then never change them again.

Code:
//what you're doing (wrong)
ahax += (accelx*5);
image.center = ahabod; // ahabod never changes!
Code:
//what to do (right)
ahax += (accelx*5);
ahabod = CGPointMake(ahax,ahay); // ahabod changes now
image.center = ahabod;
If ahax and ahabod were objects then this might work the way you expected, but ints, floats, and CGPoints are not objects.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-19-2011, 03:27 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 83
vogueestylee is on a distinguished road
Default

hi Smasher, thank you, for your answer,

it seems working when i write:

xacc = acceleration.x;

instead of:

NSString *xacc = [[NSString alloc] initWithFormat:@"%g", acceleration.x];

(because i want have an info on LabelText about value..)

so, is there any good way how to define (void) that will go
only first time and then never repeat in program?


ok and if i can, one basic question:

i have function -(void)movepicture {..}

and want use this functin in -(void)gameloop {..}

but.. in gameloop it says - movepicture undeclared.. how to declare it? in .h file? i don't know to syntax..

EDIT: ok , i found it: it is not movepicture; but
- (void)gameLoop {

[self movepicture];

..i need study more about objects i think...

Last edited by vogueestylee; 02-19-2011 at 04:04 PM.
vogueestylee is offline   Reply With Quote
Old 02-19-2011, 05:09 PM   #4 (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=vogueestylee;303152]hi Smasher, thank you, for your answer,

it seems working when i write:

xacc = acceleration.x;

instead of:

NSString *xacc = [[NSString alloc] initWithFormat:@"%g", acceleration.x];
[quote]

If you xacc to be a string, then the second one is correct. This first one works if xacc is a float or int.

Quote:
so, is there any good way how to define (void) that will go
only first time and then never repeat in program?
Can you ask again, in a different way? I don't know what "define (void)" means. When you see "void" in Objective-C it usually refers to a method that returns nothing.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-19-2011, 06:28 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: Chicago
Posts: 29
DaveM is on a distinguished road
Default

Quote:
Originally Posted by vogueestylee View Post
hi, i'm new there so hi all

it seems to be quality forum so i will try, maybe somebody will give me an answer, i'm new to programming and have (maybe stupid) question:

is the viewDidLoad {} function goes only for first time of app start?
Have you tried setting a breakpoint in XCode and debugging? Or at the very least, writing print statements and checking the console?
DaveM is offline   Reply With Quote
Old 02-20-2011, 05:06 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 83
vogueestylee is on a distinguished road
Default

Quote:
Originally Posted by DaveM View Post
Have you tried setting a breakpoint in XCode and debugging? Or at the very least, writing print statements and checking the console?
Hi all, this is good idea. when i was just curious, what is stored in "acc.x" i made a label a set writing a number on it, bud it was just for check the value, i think, there must be the way that appliciation is running in my mobile (emulator) and on the macbook i see value of acc.x for example on console or so on.. how to do that? it will save a lot of time of not doing these unnecessary Label on iphone screens..


Smasher - what i was thinking, you run the application, it set up image basic coordinates to 150.0,150.0 and show the pictire, but then it never again set up 150.0,150.0 but coordinates stay 150.0,150.0 or are changed by any other void in application. do you understand better what i'm affraid of? to not set up it again in the middle of program, bud i maybe understood what you wrote that - if i don't "close" the actual view, then viewDidLoad goes only once (what i need) and NSTimer loop goes "for ever" (what i need)..

i now "playing" with moving of picture should see more realistic, need to implement speed + acceleration*time^2 something like that, bud having problems with time, really have no clue how to set it and read it and how to set an inertia to object so maybe i will ask later
vogueestylee 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
8 members and 419 guests
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