开发者

controlling movement of image in iphone game

开发者 https://www.devze.com 2023-01-14 13:49 出处:网络
i have one code which moves the uiimageon touch-event it\'s like this: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

i have one code which moves the uiimage on touch-event

it's like this:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[[event allTouches]anyObject];
touchOffset= image.center.x-[touch locationInView:touch.view].x;
}


-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[[event allTouches]anyObject];
//paddle movemant coordinates
float distanceMoved=([touch locationInView:touch.view].x+touchOffset)- image.center.x;
float newX= image.center.x+distanceMoved;
if(newX>30 &&newX<290)
image.center=CGPointMake(newX, image.center.y);
if(newX>290)
image.center=CGPointMake(290, image.center.y);
if(newX<30)
image.center=CGPointMake(30,  image.center.y);
}

BUT the problem is that I want this action must be perform on button(lef开发者_开发问答t-right button)action.When ever I pressed the left button UIImage move little bit to left side. And When ever I pressed the Right button UIImage move little bit to right side basically I want image movement controller with button only on x axis of iphone or pad.

thanks in advance


CGRect frame = [image frame];
frame.origin.x += 10.0f;
[image setFrame:frame];


CGRect frame = [image frame]; frame.origin.x += 10.0f; [image setFrame:frame]; use this & map your buton actions with it .

0

精彩评论

暂无评论...
验证码 换一张
取 消