Game Development Community

Accelerometer Camera Scrolling on ITGB

by Ashley Leach · in iTorque 2D · 07/31/2009 (8:44 am) · 5 replies

Hey guys,

Im having a small issue with my Camera Scrolling using the Accelerometer,
i tied it to the $gravity call (im just writing on top of the iPhoneTest)

The code works in windows ITGB with the joystick
The code works in OSX if i set the $gravity variable in the console (osx doesnt have joystick support)
on the Iphone i get the accelerometer value rendering correctly (its outputting to a gui control) so i know it has the $gravity value set but the screen doesnt move

the code im using is below

function t2dSceneGraph::onUpdateSceneTick() {
   fpsGUICtrl.setText( "FPS:" SPC $fps::real SPC "mspf:" SPC 1000 / $fps::real SPC " images:" SPC $Gravity.x SPC $Gravity.y );
   echo($Gravity.x SPC $Gravity.y);
   
   %sceneWindow = sceneWindow2d;  
   %sceneWindow.setCurrentCameraPosition((%sceneWindow.getCurrentCameraPosition().x + $Gravity.x),
                                        (%sceneWindow.getCurrentCameraPosition().y + $Gravity.y));  
  %sceneWindow.startcameramove(0);

}


any help appreciated.

#1
07/31/2009 (9:26 am)
seems like it should work. In my game I had to have a camera following the character. so I just mounted the camera to the character.
You can try to do the same thing, control the character with $Gravity and just mount the camera to it. once you know it's working, you can change the character from sprite to t2dSceneObject.
Also, make sure you setUsedPhysics(1)
#2
07/31/2009 (11:04 am)
I would suggest echoing out the various variables you are using to make sure they are what you think they are.

Also, taking a quick peak at the engine code for startCameraMove, I think the variable you push in is the movement speed. You're putting in a speed of 0... try something higher, like 50.

Also, I would highly suggest putting this functionality into the C++ engine code, not in script, as it could help things to run faster.
#3
07/31/2009 (7:16 pm)
@eyal, what object would i call setUsedPhysics on if its the camera?

@dave: the variable is interp time, so zero is pretty much instant (plus i tested this on two other platforms and they worked)

It turns out that t2dSceneGraph::onUpdateSceneTick() isnt being called on the device, no idea why, ill investigate that later, but for now ill just use a tick schedule to solve this.

Thanks Eyal and Dave :)

Cheers,
Ash
#4
08/01/2009 (1:57 am)
Hrm... try calling sceneWindow2d.setUsesPhysics(1);... that might be the right object in this case to activate physics on.

There are 2 main things that my half-awake, inebriated brain can think of here...

1.) If physics has not been activated for an object, it usually will not move on the iPhone.
2.) You need to make sure that scene tick updates are enabled for the object. Perhaps give sceneWindow2d.enableUpdateCallback(); a try and see if that gets them moving!
#5
08/01/2009 (7:35 am)
I'm not sure if you can run setUsesPhysics on sceneWindow2d, but that's what I would try too. sounds like it's the right object to try it on. when you setCurrentCameraPosition you don't need to startCameraMove, it should move instantly. open the console and try it from cmd. if you can't figure it out, try the t2dSceneObject and mount your scenceWindow to it. this definitely works. at least you'll be able to move on for now.