skrekkur wrote:
Hi That code is not related to the camera position, only the object position. If you are making your own stuff it could be a nice idea to abstract the camera and let it have its own class that you can position.
In the demo, positionoffset controls the camera position.
Try looking at
Code:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
in Box2dView
if you want the camera to follow an object you have to set this positionoffset to match the position of the ball ( or whatever object) in each loop.
Hope this helps.
Oh ok i see, i am only learning about this stuff and its trial and error, mostly error...
🙁 This is the code i have right now,
Code:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
for (UITouch *touch in touches)
{
CGPoint touchLocation=[touch locationInView:self];
CGPoint worldPosition=[self screenSpaceToWorldSpace:touchLocation];
//printf("Screen touched %f,%f -> %f,%f\n",touchLocation.x,touchLocation.y,worldPosition.x,worldPosition.y);
CGPoint screenDistanceMoved=CGPointMake(touchLocation.x-lastScreenTouch.x,touchLocation.y-lastScreenTouch.y);
if (panning)
{
screenDistanceMoved.x/=160;
screenDistanceMoved.y/=160;
screenDistanceMoved.x*=sceneScale;
screenDistanceMoved.y*=-sceneScale;
positionOffset.x+=screenDistanceMoved.x;
positionOffset.y+=screenDistanceMoved.y;
}
lastScreenTouch=touchLocation;
lastWorldTouch=worldPosition;
test->MouseMove(b2Vec2(lastWorldTouch.x,lastWorldTouch.y));
}
So how do i change that to follow say a circle on screen (a ball)? Do i need to change positionOffset.x+=screenDistanceMoved.x;positionOffset.y+=screenDistanceMoved.y; ?? and how do i find the position of my ball to put that in? or do you have to link it to the object?
Thank you for the reply though...