Game Development Community

New to iTorque 2D and having problems....Need help :(

by Celso Duran · in iTorque 2D · 08/02/2011 (10:52 am) · 7 replies

Like the Title says, I'm pretty new to iTorque 2D, but I'm in no way new to software development on the iPhone/iPad or any system for that matter.

Here's what I did:

As my first test into working with TGB I created a graphical D-Pad made up of 5 images, a center image and 4 arrow images. In TGB I went into the "Scripting" tab and enabled "Use Mouse Events" for each of the images and entered "ControlClass" for the class each image belongs to. In the "Dynamic Fields" tab I created a field named "direction" and gave each image a different numeric value.

Then, in the game.cs script file I added the following code to test it all out:

// This function is already in the script I just added the 'echo'
function oniPhoneTouchUp( %touchCount, %touchX, %touchY )
{
echo("Stop!!!");
}


function ControlClass::onMouseDown(%this, %modifier, %worldPos)
{
switch(%this.direction)
{
case 8:
echo("Up.....");
case 2:
echo("Down.....");
case 4:
echo("Left.....");
case 6:
echo("Right.....");

default:
echo("Center.....");
}
}

Now here's what happens:
When I run this I get a blank screen with a mouse arrow that moves to the location I touch on the screen. When I release the touch (oniPhoneTouchUp) I do get the output I expect, "Stop!!!", on Xcode's output terminal (is there a debug terminal that I can use without having to build the project?). I'm also getting what seems to be an error message, "oniPhoneBecomeActive: Unknown command."

Can anyone help me out with this? I've been fighting with this for days now and can't seem to figure out what the problems is. My problem is also compounded by the fact that now, no matter what changes I make to the game.cs file, the changes don't stick (ie. I commented out the echo("Stop!!!") and then later deleted it, but the line is still executed.)

#1
08/02/2011 (1:03 pm)
@Celso - Did you add your imageMaps to the level's datablocks file? An example of this process is shown in the RainyDay tutorial

Usually when objects do not show up, it is due to the fact that they are not added to the level datablocks.
#2
08/02/2011 (1:09 pm)
Yes I did add the imageMaps to the datablock's. In fact, the scene is displayed just fine if I don't add any of my own code to the game.cs file.
#3
08/02/2011 (1:37 pm)
Quote:the scene is displayed just fine if I don't add any of my own code to the game.cs file

Your code is not the problem. I just tested it and achieved the desired result.

Quote:(is there a debug terminal that I can use without having to build the project?)

If you run the iTorque2DGame.app or iTorque2DGame.exe on a desktop machine, you can open the console.log file in the same directory. This will give you all iTorque 2D specific print out, basically letting you know if there are warnings or errors.

Whether you send me that file or copy and paste from the Xcode output, I think I need to see your full console log to determine what is going on. As for changes not taking place, that's usually because a .DSO file was generated. When this happens, the engine will read the code from the DSO (which is older than what you might have in the .cs).
#4
08/02/2011 (2:26 pm)
Glad to have you on Torque Celso. Just a few things to add on top of Michael's tips.

Whenever you make a change to your game. Rebuild in TGB and then delete the .app file from xcode or else you won't see your changes.

Also you are seeing this: oniPhoneBecomeActive: Unknown command." because you don't have that function in you game code. It's a callback from the iOS when your app becomes active. Just add a blank function onIphoneBecomeActive(){}; and the message will disappear. (Michael suggest adding these callbacks to the default template)

Your app seems to work fine but something wrong with the images. Usually it's a level datablock problem that Michael pointed out. (I missed the simplicity of the old datablock system).


#5
08/04/2011 (10:18 am)
Thanks guys for all the help!

I have it all working now, my problem was that Xcode was building my app in iPhone mode and I was assuming that the display was just being scaled down when in fact the screen size was still the same but my graphics were off screen.

Now I just have one question, that small mouse cursor that appears in the simulator, how do I eliminate it? Or is it just there in simulation only?
#6
08/04/2011 (10:22 am)
@Celso - Glad you got it working. As for removing the mouse cursor, you can use this simple code.

Add to the bottom of startGame
if($platform $= "iphone")
{
   hideCursor();
}
#7
08/04/2011 (11:15 am)
That did the trick, thanks...