Game Development Community

Breakout tutorial on iPhone

by Andrew Poquette · in iTorque 2D · 04/21/2010 (9:02 pm) · 27 replies

Hello all! I'm trying to convert the Breakout tutorial(Part 1) to the iPhone, and I can't seem to get the ship to move when clicked. I have double checked that everything in TGB is set correctly, and it is.

Here is my code in game.cs:

function sceneWindow2D::onMouseMove(%this, %modifier, %worldPosition, %mouseClicks){
		movePaddle(%worldPosition);
		
	}
	
function sceneWindow2D::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks){
		movePaddle(%worldPosition);
		
	}
	
function movePaddle(%worldPosition) {
		%newXPos = getWord(%worldPosition,0);
		if (%newXPos < 0) { %posmod= -1; } else { %posmod = 1; }
		if (mAbs(%newXPos) > 65) %newXPos = %posmod * 65;
			
		$theBase.setImpulseForce((%newXPos)*$vmod,0);

		sceneWindow2D.setMousePosition("0 0");	
	}

The image map for the base is set to Class: baseClass, and Name: theBase

I finally figured out how to get the images to show up (by copying the image map from the managed file) but I can't seem to get this to work. I've been researching and trying all night, but any help is much appreciated.

Thanks,
~Andy
Page«First 1 2 Next»
#21
05/02/2010 (12:30 am)
Sure, I will upload it. Not sure how to do that yet, but I'll figure it out. BTW, I didn't optimise anything, and I didn't worry about making graphics power of 2 etc, I just ported it blindly, and it still runs on my Ipod Touch v2 very smoothly (40 to 50 fps). For a simple example, optimisation isn't an issue, and it just goes to show that the GG example is misguided. Optimisation is important, but it's a trivial problem compared to getting used to the engine in my opinion. Optimisation becomes obvious after you have a good feeling for the engine.

I'm using all of the original graphics and particle effects, and it runs great.

I was hoping to write a tutorial, but hopefully the source code will be a good help to everyone new to iTGB. Where do I up load it to?







#22
05/02/2010 (7:23 am)
Mark

You can email me the source zip file and I will host it on my webserver. I will email you the link when I have it online.
#23
05/03/2010 (4:33 pm)
Hi Dean,

I've emailed my code. I've also included a ReadMe.txt file, which explains some of the changes that I made, and why I made them. I only made a few small changes though, so it's still very much like the original.

Hopefully the code will be useful.

Thanks,
Mark
#24
05/04/2010 (5:29 am)
Thank you Mark and Dean for helping out tremendously with n00bs like me.

Hopefully I have time tonight to digest and see what I'm doing wrong.
#26
05/05/2010 (6:21 pm)
Got the file. Everything works, thanks Mark and Dean.

My question is:

Can you use the touch controls without having to create the sliderPadClass? Can you just use baseClass and call movePaddle(%worldposition)?
#27
05/05/2010 (7:15 pm)
Yes, you can do that. Actually that was what I tried first, but the problem I found is that if the touch area is too small it makes it difficult to drag the object, because the finger keeps sliding outside of the touch area. I added the touchpad so that you can easily drag the base around without needing to be so precise with the finger position.
Page«First 1 2 Next»