GLBasic forum

Codesnippets => Code Snippets => Topic started by: Dark Schneider on 2011-Mar-24

Title: iPhone AutoLock function
Post by: Dark Schneider on 2011-Mar-24
I am sure this can be useful to many, it is typical in pro games to disable the iPhone autolock while you are playing, if not you are required to touch the screen, and it can affect how your app is used (forced touchs).

For use it, simply add the iOSAuxFunc.gbas to your GLBASIC project, and the iOSAuxFunc.m to your XCode project, for example to the Other Sources folder.

Included in the iOSAuxFunc is the EnableAutoLock() function, pass FALSE to disable it and TRUE to enable it again. There is no need to call EnableAutoLock(TRUE) on exit because the iOS devices do it by its own. The typical use is:

- Do not call at beginning.
- Call EnableAutoLock(FALSE) at start of GAMEPLAY.
- If paused, call EnableAutoLock(TRUE). When return to game call EnableAutoLock(FALSE).
- When gameplay ends (return to main menu, etc.), call EnableAutoLock(TRUE).

As summary, set AutoLock = OFF ( EnableAutoLock(FALSE) ) ONLY while playing, is the way iPhone games does it mainly.

[attachment deleted by admin]
Title: Re: iPhone AutoLock function
Post by: bigsofty on 2011-Mar-24
Ha! Well done, I was just thinking about this functionality last night, thank you!  :booze:

Cheers,


Ian
Title: Re: iPhone AutoLock function
Post by: Crivens on 2012-Feb-09
Phew glad I found this. My latest game has this problem when dimming (didn't notice while testing as my phone dims after 5 minutes and I don't know anyone who can survive my game for that long). Will have to do an update.

Out of interest any idea how to do the same thing on Android and WebOS?

Cheers
Title: Re: iPhone AutoLock function
Post by: tatakamucher on 2012-Feb-16
i used too, its great  :D
Title: Re: iPhone AutoLock function
Post by: Crivens on 2012-Feb-24
Just got round to using this and it works as advertised. Nice! Anyone found a WebOS or Android solution yet?

Only thing I found when I compiled it was this message:-
Code (glbasic) Select
*** Configuration: IPHONE ***
precompiling:
GPC - GLBasic Precompiler V.9.829 SN:48b9de4b - 3D, NET
Wordcount:4391 commands
compiling:
arch:
/cygdrive/q/Compiler/platform/iPhone/bin/arm-apple-darwin9-libtool: file: gpc_temp5.o has no symbols
/cygdrive/c/Program Files/GLBasic/Compiler/platform/iPhone/bin/arm-apple-darwin9-libtool: file: C:\Users\Crivens\AppData\Local\Temp\glbasic\output.obj(gpc_temp5.o) has no symbols


I've read on the forums this doesn't matter, but it's always nice to be rid of any problems. I assume it's something to do with the "(int value)" variable for the main function, mainly because my other iOS functions in other projects don't have variables and compile perfectly fine. Is there a better way to declare variables to stop the "has no symbols" message? It's not so bad with one function but would suck if you used a lot and had to scroll through messages.

Cheers
Title: Re: iPhone AutoLock function
Post by: Kitty Hello on 2012-Mar-20
in your files-pane, how many files do you see? There should be 6 of them. If there are only 5, delete the file that is reporting the warning.
Or: In file #6 (first is main program, which translates to gpc_temp0.cpp) write something like SUB summy:; ENDSUB.
Title: Re: iPhone AutoLock function
Post by: mrplant on 2012-Mar-31
The Objective C code reads:

if (value) {
   [UIApplication sharedApplication].idleTimerDisabled = NO;
} else  {
   [UIApplication sharedApplication].idleTimerDisabled = NO;
   [UIApplication sharedApplication].idleTimerDisabled = YES;
}

Is there any reason for setting the value to NO then immediately to YES underneath - or is this just a remnant from testing?

Anyway - great routine  - very very useful for iOS apps.

cheers