首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SpriteKit中的常量移动

SpriteKit中的常量移动
EN

Stack Overflow用户
提问于 2013-10-10 11:34:03
回答 10查看 17.2K关注 0票数 19

我有一个游戏,我想根据用户触摸屏幕的左侧或右侧来向左或向右移动SKNode。如何在用户触摸屏幕时对节点应用恒定移动?

EN

Stack Overflow用户

发布于 2014-08-02 20:02:16

如果您的SKNode具有physicsBody,请对其施加强制:

代码语言:javascript
运行
复制
@interface GameScene()

@property (nonatomic) CGVector force;

@end

@implementation GameScene

- (void)update:(CFTimeInterval)currentTime {
    [self.player.physicsBody applyForce:self.force];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.sideForce = CGVectorMake(3000, 0);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    self.sideForce = CGVectorMake(0, 0);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    self.sideForce = CGVectorMake(0, 0);
}

@end

如果没有,请使用LearnCocos2D的答案。

票数 0
EN
查看全部 10 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19286610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档