Touch Area on IPhone
-
- Posts: 13
- Joined: Sun Sep 19, 2010 5:04 am
- Contact:
Touch Area on IPhone
Hello
I am using chipmunk for a IPhone 2D game...and it is working amazingly..
while though, i am using 2D images of cars for my game which come from left, right, up and down in the game...the size of the images is small which is 18*32..
after running the game on iPhone i found that the touch area is too small and thus i would like to know as to how do get the touch area and not the collision area increased...
the below code shows the area defined...
vehicle->vehicleBody = cpSpaceAddBody(commonDataRef->chipSpace, cpBodyNew(1.0f, cpMomentForBox(vehicle->mass, 18.0f, 32.0f)));
vehicle->vehicleBody->p = vehicle->position;
vehicle->vehicleBody->v = vehicle->velocity;
cpBodySetAngle(vehicle->vehicleBody, DEGREE_TO_RAD(vehicle->angle));
vehicle->vehicleShape = cpSpaceAddShape(commonDataRef->chipSpace, cpBoxShapeNew(vehicle->vehicleBody, 18.0f, 32.0f));
vehicle->vehicleShape->e = 0.0f;
vehicle->vehicleShape->u = 0.8f;
but if i increase the area 18 and 32 the collision area also increases...Please Advice
I am using chipmunk for a IPhone 2D game...and it is working amazingly..
while though, i am using 2D images of cars for my game which come from left, right, up and down in the game...the size of the images is small which is 18*32..
after running the game on iPhone i found that the touch area is too small and thus i would like to know as to how do get the touch area and not the collision area increased...
the below code shows the area defined...
vehicle->vehicleBody = cpSpaceAddBody(commonDataRef->chipSpace, cpBodyNew(1.0f, cpMomentForBox(vehicle->mass, 18.0f, 32.0f)));
vehicle->vehicleBody->p = vehicle->position;
vehicle->vehicleBody->v = vehicle->velocity;
cpBodySetAngle(vehicle->vehicleBody, DEGREE_TO_RAD(vehicle->angle));
vehicle->vehicleShape = cpSpaceAddShape(commonDataRef->chipSpace, cpBoxShapeNew(vehicle->vehicleBody, 18.0f, 32.0f));
vehicle->vehicleShape->e = 0.0f;
vehicle->vehicleShape->u = 0.8f;
but if i increase the area 18 and 32 the collision area also increases...Please Advice
-
- Posts: 81
- Joined: Fri Aug 27, 2010 1:00 am
- Contact:
Re: Touch Area on IPhone
Hi
quick thought on your problem: I don't see why it is related to chipmunk.
The shape is how your object is defined in the physical world of chipmunk so in itself it has little to do with your area of touch.
I think your issue is more located in the "how to convert touch to chipmunk" type of problem
I would suggest you approach your problem by defining a touch zone that you can test for overlapping with the position of the shape
if you insist on continuing with different shape size for touch and collision, why not define 2 shapes in 2 different groups (so that they don't trigger collisions between them selves)
and you use the second group to be A) bigger that the one you use for collisions B) handle only you touch.
Hope that helps
Jason
quick thought on your problem: I don't see why it is related to chipmunk.
The shape is how your object is defined in the physical world of chipmunk so in itself it has little to do with your area of touch.
I think your issue is more located in the "how to convert touch to chipmunk" type of problem
I would suggest you approach your problem by defining a touch zone that you can test for overlapping with the position of the shape
if you insist on continuing with different shape size for touch and collision, why not define 2 shapes in 2 different groups (so that they don't trigger collisions between them selves)
and you use the second group to be A) bigger that the one you use for collisions B) handle only you touch.
Hope that helps
Jason
-
- Posts: 13
- Joined: Sun Sep 19, 2010 5:04 am
- Contact:
Re: Touch Area on IPhone
i am using this piece of code to get which object i have touched..
NSMutableArray vehicleObj;
cpShape *shape = cpSpacePointQueryFirst(commonDataRef->chipSpace, engRefProgMod->touchPoint, GRABABLE_MASK_BIT, CP_NO_GROUP);
if(shape)
{
for(CVehicle *tmpVec in vehicleObj)
{
if(tmpVec->vehicleDirectionType == VEHICLE_DIRECTION_TB)
{
if(shape->body == tmpVec->vehicleBody)
tmpVec->vehicleBody->v = cpv(0,300);
}
}
}
and the area is defined as shown in the above post..
I am checking which object i have touched through this..i just want the touch area bigger..
as the image is small..
NSMutableArray vehicleObj;
cpShape *shape = cpSpacePointQueryFirst(commonDataRef->chipSpace, engRefProgMod->touchPoint, GRABABLE_MASK_BIT, CP_NO_GROUP);
if(shape)
{
for(CVehicle *tmpVec in vehicleObj)
{
if(tmpVec->vehicleDirectionType == VEHICLE_DIRECTION_TB)
{
if(shape->body == tmpVec->vehicleBody)
tmpVec->vehicleBody->v = cpv(0,300);
}
}
}
and the area is defined as shown in the above post..
I am checking which object i have touched through this..i just want the touch area bigger..
as the image is small..
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Touch Area on IPhone
In that case, don't use Chipmunk queries to pick your objects. Just find the closest object to the touch within a certain radius.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 13
- Joined: Sun Sep 19, 2010 5:04 am
- Contact:
Re: Touch Area on IPhone
Thank You for the valuable reply...
- pat
- Posts: 53
- Joined: Tue Jul 20, 2010 7:55 pm
- Contact:
Re: Touch Area on IPhone
You could also do like a vertical or horizontal segment query too. then in the callback function choose the one closest to the touch point. otherwise yea, you could iterate the active/static shape hash choosing the closest within a radius of the touch point.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Touch Area on IPhone
I'm not sure if the "..." was implying sarcasm or not, but I'm quite serious.
Presumably you keep a list of objects in your game. It would be much easier to just make a simple for loop to find the nearest object to the touch, then reject the object if it's farther than a certain distance away. Certainly much easier than trying to maintain two sets of Chipmunk collision objects and deal with the associated overhead of keeping them up to date but never generate collisions.
Presumably you keep a list of objects in your game. It would be much easier to just make a simple for loop to find the nearest object to the touch, then reject the object if it's farther than a certain distance away. Certainly much easier than trying to maintain two sets of Chipmunk collision objects and deal with the associated overhead of keeping them up to date but never generate collisions.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 13
- Joined: Sun Sep 19, 2010 5:04 am
- Contact:
Touch Area on IPhone
Hello Sir
well, i have a small query, i know this is not chipmunk related.. i just looking for an advice
there are two objects traveling in a straight line with varying velocities,
1. how to detect that some object is at the front
2. if my object which is ahead is traveling at a slow speed than the object which is at the back, it should gradually slow down and move along with it...
Thanks
I was just being thankful sir.I'm not sure if the "..." was implying sarcasm or not
well, i have a small query, i know this is not chipmunk related.. i just looking for an advice
there are two objects traveling in a straight line with varying velocities,
1. how to detect that some object is at the front
2. if my object which is ahead is traveling at a slow speed than the object which is at the back, it should gradually slow down and move along with it...
Thanks
-
- Posts: 81
- Joined: Fri Aug 27, 2010 1:00 am
- Contact:
Re: Touch Area on IPhone
Hi
I would suggest this:
you can get for a given object its position p and velocity v.
this should give you all the information you need to determine the wich one is in front of the other
cpVect aVector = p1-p2;
if(aVector.v>0){
//aVector is in the same direction as v => p1 in front of p2
// <-(v)-p1<-------p2
}else{
//aVector is in the opposite direction as v => p2 in fornt of p1
// p1<-------p2-(v)->
}
this works with v of p1 or p2 since there are going in the same direction
onc eyou have that it is a simple matter of applying forces to slow down the body in front of the other
hope this helps
Jason
FYi (for your information, if you add "..." like you did, you give the impression that you have not finished what you wanted to say, so if you put it after your "thank you for your valuable reply" it sounds like you don't think that the reply was relevent or complete; this in turn leads to the reader thinking your are being sarcastic. (but we are not here to discuss English linguisitcs ^^)
I would suggest this:
you can get for a given object its position p and velocity v.
this should give you all the information you need to determine the wich one is in front of the other
cpVect aVector = p1-p2;
if(aVector.v>0){
//aVector is in the same direction as v => p1 in front of p2
// <-(v)-p1<-------p2
}else{
//aVector is in the opposite direction as v => p2 in fornt of p1
// p1<-------p2-(v)->
}
this works with v of p1 or p2 since there are going in the same direction
onc eyou have that it is a simple matter of applying forces to slow down the body in front of the other
hope this helps
Jason
FYi (for your information, if you add "..." like you did, you give the impression that you have not finished what you wanted to say, so if you put it after your "thank you for your valuable reply" it sounds like you don't think that the reply was relevent or complete; this in turn leads to the reader thinking your are being sarcastic. (but we are not here to discuss English linguisitcs ^^)
Who is online
Users browsing this forum: No registered users and 18 guests