Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

my sprite can move up and down but some probs are there.......

sprite is moving slowly , i want some speed in moving the sprite

sprite is not continue move but jumping .....

sprite can not touch upper and lower limit of the screen

here is code i tried......

 -(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{   

[_runeman setPosition:ccp(_runeman.position.x  , _runeman.position.y + acceleration.x * 10)];

}

annd in upload method....

CGSize winSize = [CCDirector sharedDirector].winSize;
float imageHeightHalved = [_runeman texture].contentSize.height * 0.25f;
float downLimit = imageHeightHalved + 12 ; 
float upLimit = winSize.height - imageHeightHalved - 12 ;

pos  = _runeman.position;
pos.y += vel.y;

if (pos.y > upLimit) {
    pos.y = upLimit;
    vel = CGPointZero;
}else if (pos.y < downLimit) {
    pos.y = downLimit;
    vel.y = downLimit;
}
_runeman.position = pos;
share|improve this question

2 Answers

you can see here for more example about velocity game racing https://github.com/RacingTadpole/Cocos2D-Box2D-MVC-example

share|improve this answer

As for the jumping instead of slowly moving, movement of an object across the screen is always going to be visualized by a change in pixels being drawn. If you simply update the position each frame, the object will automatically jump to that position. Verify the units you are getting from the device, and chances are you need to implement change in time into the equation yourself.

For the screen clipping, verify the orientation of your screen coordinates. Standard OpenGL coordinate system for the screen uses 0,0 as the bottom left, and 1,1 as the top right. This could be different on the IOS platform. Also, you seem to be zeroing out your velocity when evaluating a collision with the top of the screen, but not with the bottom.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.