Page 1 of 1

Updating Screen Boundaries

Posted: Thu May 27, 2010 9:14 pm
by ArtDev
Hey Guys,

I'm working on a game for the iPhone that right now is just a background and some screen boundaries the back ground is currently 640x960 which is twice the size of the iphone screen so that the background has to move around depending on where the user is at...I've got this working the background moves just fine, what I can't get is the screen boundaries to move...they are normal screen boundaries found on the many examples in this forum.


floorBody = cpBodyNew(INFINITY, INFINITY);
leftWallBody = cpBodyNew(INFINITY, INFINITY);
rightWallBody = cpBodyNew(INFINITY, INFINITY);
ceilingBody = cpBodyNew(INFINITY, INFINITY);
cpShape* floorShape = cpSegmentShapeNew(floorBody, cpv(-160,0), cpv(480,0), 1);
floorShape->e = 0.6;
floorShape->u = 0.3;
floorShape->collision_type = 0;
cpSpaceAddShape(space, floorShape);

floorShape = cpSegmentShapeNew(leftWallBody, cpv(-160,0), cpv(-160,960), 1);
floorShape->e = 0.6;
floorShape->u = 0.3;
floorShape->collision_type = 0;
cpSpaceAddShape(space, floorShape);

floorShape = cpSegmentShapeNew(ceilingBody, cpv(-160,960), cpv(480,960), 1);
floorShape->e = 0.6;
floorShape->u = 0.3;
floorShape->collision_type = 0;
cpSpaceAddShape(space, floorShape);

floorShape = cpSegmentShapeNew(rightWallBody, cpv(480,0), cpv(480,960), 1);
floorShape->e = 0.6;
floorShape->u = 0.3;
floorShape->collision_type = 0;
cpSpaceAddShape(space, floorShape);
//End Screen Boundaries

I've read the documentation and it says to not update the body per step but I don't know how else to change the position of the boundaries... if anyone could point me in the right direction I would appreciate it.

Thank you in Advance

Re: Updating Screen Boundaries

Posted: Thu May 27, 2010 9:55 pm
by slembcke
I'm not sure I understand. You want the screen boundaries to move? Like as if the objects were placed inside a box and you were moving the box around with the objects inside of it? Somehow I'm thinking this isn't really what you want though.

You can move the position of a body every frame if you update its velocity to match (position delta divided by time).

Re: Updating Screen Boundaries

Posted: Fri May 28, 2010 11:28 am
by Tam Toucan
the background has to move around depending on where the user is at
Sounds like he wants to move where the draw position is depending on where the player is. e.g. draw the world so that the user is always in the middle. If that's what you mean then you've got it the wrong way around. You draw the world relative to the player, you don't move the rest of the world. If you think about it the boundary walls stay still and it's the viewpoint (camera if you like) that moves.