标题:ccsprite touch 事件
只看楼主
qq236533067
Rank: 2
等 级:论坛游民
帖 子:14
专家分:14
注 册:2011-5-13
 问题点数:0 回复次数:3 
ccsprite touch 事件
请问问下,为啥我的精灵无法移动?请指教。代码上传了。
程序代码:
//
//  GoodsSprite.m

//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "GoodsSprite.h"


@implementation GoodsSprite
-(id)init
{
    if(self=[super init])
    {
        GoodsArray=[[CCArray alloc]initWithCapacity:40];
        CCSprite *weapon=[CCSprite spriteWithFile:@"weapon.png"];
        weapon.scale=0.46f;
        [GoodsArray addObject:weapon];
        CCSprite *clothes=[CCSprite spriteWithFile:@"clothes.png"];
        clothes.scale=0.46f;
        [GoodsArray addObject:clothes];
        CGSize size = [[CCDirector sharedDirector] winSize];
        float x=205,y=size.height-70;
        for(int i=0;i<2;i++)
        {
            x+=50;
            CCSprite *temp=[CCSprite node];
            temp=[GoodsArray objectAtIndex:i];
            temp.position=ccp(x, y);
            [self addChild:temp z:0 tag:101+i];
            
        }
        
    }
    return self;
}
+(id)GoodsSpriteWithRect:(CGRect)rect spriteManager:(CCSprite *)manager
{
    id rtn = [[[self alloc] initWithTexture:manager.texture rect:rect] autorelease];
    
    return rtn;
}
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
    if(![self containsTouchLocation:touch])
    {
        return NO;
    }
    return YES;
}
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint touchPoint = [touch locationInView:[touch view]];  
    touchPoint = [[CCDirector sharedDirector] convertToUI:CGPointMake(touchPoint.x, touchPoint.y)];  
    self.position = CGPointMake(touchPoint.x, touchPoint.y); 
}
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    
}
-(void)onEnter
{
    [[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES];
    [super onEnter];
}
-(void)onExit
{
    [[CCTouchDispatcher sharedDispatcher]addTargetedDelegate:self priority:0 swallowsTouches:YES];
    [super onExit];
}
-(CGRect)rect
{
    return CGRectMake(-rect_.size.width / 2, -rect_.size.height / 2, rect_.size.width, rect_.size.height);
}
-(BOOL)containsTouchLocation:(UITouch *)touch
{
    
    return CGRectContainsPoint(self.rect, [self convertTouchToNodeSpaceAR:touch]);
}
-(void)dealloc
{
    [super dealloc];
}
@end

[attach]65347[/attach]

[ 本帖最后由 qq236533067 于 2012-10-22 16:14 编辑 ]
搜索更多相关主题的帖子: touch 精灵 Copyright clothes import 
2012-10-08 13:23
qq236533067
Rank: 2
等 级:论坛游民
帖 子:14
专家分:14
注 册:2011-5-13
得分:0 
求大神帮助啊。。。是不是我touchbegan那个方法里的获取有问题?求帮助,求解答!!
2012-10-09 08:13
qq236533067
Rank: 2
等 级:论坛游民
帖 子:14
专家分:14
注 册:2011-5-13
得分:0 
看来这板块没啥人啊。。。还好我自己想到办法解决了。。。
2012-10-09 15:48
foktime
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:奥斯维辛
等 级:贵宾
威 望:35
帖 子:795
专家分:2742
注 册:2009-9-4
得分:0 
2012-11-17 23:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382709-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021706 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved