Game Development Community

TBG to iTBG....a few questions

by john m ingato · in iTorque 2D · 11/19/2009 (3:20 pm) · 10 replies

Hi, I'm about to bring my game over to a mac to put it on the iphone. I just have a few questions before I get started.

1. In my game I am saving the level data to a .cs file using the command levelList.save($levelPath); Will that still work on the iphone? Do I need to know where it saves it to? And will people have access to the files at this location?

2. In my gui I have GuiBitmapButtonCtrl()'s with Command = "myFunction();". Will this still work on the iphone. I'm hoping that it will translate into having to tap the screen on the button instead of clicking with the mouse.

3. How do people usually implement a pause button. Right now I have the escape key pausing the game. Obviously there is no escape key on the ipone. Do I need to put a visual pause button on the screen somewhere?

Thanks

-John

#1
11/19/2009 (9:49 pm)

2) Saving will work but you can never use them again as you can't compile scripts on the iphone, only on your desktop

3) Yes if you want to have one then you better have
#2
11/20/2009 (1:46 am)
Can you expand on the saving issue? Is that not the right way to save stuff like which levels are unlocked on the iphone. It's just a simset in a .cs file. What do you mean by compile it? Do you mean as a .dso? I don't need it to do that. Just save it as a .cs, or should I be using .txt files instead?
#3
11/20/2009 (3:45 am)
Hey John,

1) This will not work as is on the iPhone. The reason being that you cannot modify the actual location where the game is stores. ALTHOUGH, there is a function in the engine (at least, i know that it is in the new release coming soon) that is name getAppDocumentsPath. On iPhone, every application has its OWN section to store documents and data. The data is "safe" from the user perspective but the users who use pirated apps - can access the data. a simple binary format can do the trick, or a simple encryption/decryption scheme can be employed as well. you can do something along the lines of (for text or binary) :

%fileLocation = getAppDocumentsPath() @ "/myfile";
%filehandle = new FileObject(%fileLocation);

//Either file.write or file.writeline , etc
%fileHandle.write(%someData); 

%filehandle.close();
delete %filehandle;

Although you should also be able to save the level lists with the specific location (not something relative, like ~/data/levelsaves

The second place to store the values/information is in the system "registry" which is also, per application. The function called saveGameDataToDevice("values" , " keyname"); will use the OS to store values away from the user as well (same deal with the jailbreakers, though).

We used a simple encryption, and store the encrypted string in the registry.

2)Gui's will work as expected

3) You will need a pause function, a pause button and a resume function. The 3 need to cater for the system as well. When a user presses the LOCK button (power button on the iPhone) it goes into standby mode and turns the screen off - which minimizes your game. If your game does not implement the iPhone functions for didBecomeActive and willResignActive - the game will not pause. The new release (coming soon) supports this script side as well, and manages the pausing / resuming wholely.

And yes, you need a button on screen
#4
11/20/2009 (11:04 am)
To elaborate on point 1: Nobody should ever save to the install path, ever, on any platform ;)

There are already functions to handle most (all?) of this stuff in the current beta engine, but I hope you guys give it the once-over to ensure it's as easy as possible to store data, and not necessary to know where to do it. Optimally, T2Di should just pick one location for the user to save to, and use that path as the first of two to read from (the other being the game directory).
#5
11/20/2009 (2:52 pm)
ok, thanks for the tips guys. SO I can't use the save function I've been using. So say I use %fileHandle.write(%someData); as mentions in Sven's post. Can %someData equal a simSet or does it need to equal a string? Also, will it erase the current info in the file and overwrite it? Also, how do I import that. Do I exec the file or do I do I need to use some other function to open it and access the saved simSet?

Thanks again

btw I'm using the 1.3 beta if that matters
#6
11/20/2009 (5:04 pm)
Ronny, the application directory is for that (the Documents path). Thats what it was created for, and it does look there depending on "what its looking for". We could probably use something like ">/game/data/image/downloadedImage1.png" , where the > expands to the path for application data. although, even better is to just use ~/ as normal - on iPhone it just looks to *SAVE* files in the directory on the device. this keeps windows and iphone checking all the time to a minimum.

@John
The FileObject is a full fledged file access class (as you would expect from normal programming API's etc). For example, we use a custom binary format for the levels in one game - which is implemented code side but can be done in script as well - its up to you where to do it. If you made a save game function : it can save to the application documents path. CAN SAVE. So what you are doing now should be OK! just, you need to give it a location that has write access. This location is determined by the iphone side and is currently not in 1.3, but if it is a pressing issue let me know i can probably help to get that getAppDocumentsPath exposed your side.
#7
11/20/2009 (8:05 pm)
I set $levelPath = "data/saves/leveldata_mod.cs";

is that OK?


I set it up the same as this tutorial

tdn.garagegames.com/wiki/TGB/BreakoutTutorial5
#8
11/21/2009 (3:12 am)
Well, its not ok right now. Because it will save to the data folder inside the application (which is not even allowed, so it fails to save).

You normally do :

%savePath = getAppDocumentsPath();
$levelPath = %savePath @ "data/saves/leveldata_mod.cs";

But in the beta, i don't think the getAppdocumentsPath existed. I might be able to post the function in the forums a little later for you to use.
#9
11/21/2009 (8:19 am)
that would be great!
#10
11/24/2009 (12:59 pm)
Hey Sven, any luck finding that getAppDocumentsPath() function?