- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在我的 Spritekit 游戏中实现这种效果,其中角色后面有一条平滑轨迹。
在喷气背包兜风中查看硬币背后的踪迹:
木星跳跃中英雄背后的这条踪迹:
或者《Ski Safari》中英雄身后的这条 super 平滑的小路:
这似乎是其他游戏引擎的标准功能?我认为 spritekit 粒子发射器只会提供 block 状/标记的轨迹,而不是平滑的轨迹。我应该使用某种 Sprite 自定义着色器吗?还有其他创意吗?
最佳答案
您的问题没有包括要使用的运动类型这一关键问题。我的答案是基于触摸屏幕到达目的地,但另一种选择是使用核心运动。无论使用哪种方法,基本代码原理都是相同的。只有实现会改变。
我在示例中使用了矩形尾部图像,因为我希望您能够复制并运行示例代码。您应该用圆形图像/纹理替换矩形,以使尾部的侧面更平滑。
修改 fadeOutDuration 值将导致更长或更短的持续尾部。
修改stepsDivider将导致尾部节点增多或减少。
#import "GameScene.h"
@implementation GameScene {
SKSpriteNode *playerNode;
CGPoint destinationPoint;
NSMutableArray *myArray;
NSMutableArray *myDiscardArray;
BOOL working;
int numberOfSteps;
float xIncrement;
float yIncrement;
float fadeOutDuration;
int stepsDivider;
}
-(void)didMoveToView:(SKView *)view {
self.backgroundColor = [SKColor blackColor];
playerNode = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:CGSizeMake(30, 30)];
playerNode.position = CGPointMake(200, 200);
[self addChild:playerNode];
myArray = [[NSMutableArray alloc] init];
myDiscardArray = [[NSMutableArray alloc] init];
working = false;
fadeOutDuration = 0.5;
stepsDivider = 10;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
if(working == false) {
destinationPoint = location;
if(fabsf(location.x - playerNode.position.x) > fabsf(location.y - playerNode.position.y)) {
numberOfSteps = fabsf(location.x - playerNode.position.x) / 10;
} else {
numberOfSteps = fabsf(location.y - playerNode.position.y) / 10;
}
xIncrement = (location.x - playerNode.position.x) / numberOfSteps;
yIncrement = (location.y - playerNode.position.y) / numberOfSteps;
working = true;
}
}
}
-(void)update:(CFTimeInterval)currentTime {
if (working == true) {
// create trail node at current player's position
SKSpriteNode *myNode = [SKSpriteNode spriteNodeWithColor:[SKColor whiteColor] size:CGSizeMake(30, 30)];
myNode.position = playerNode.position;
[self addChild:myNode];
[myArray addObject:myNode];
[myNode runAction:[SKAction fadeOutWithDuration:fadeOutDuration]];
// check array for any nodes with zero alpha
for(SKSpriteNode *object in myArray) {
if(object.alpha == 0) {
[myDiscardArray addObject:object];
}
}
// remove zero alpha nodes
if([myDiscardArray count] > 0) {
[myArray removeObjectsInArray:myDiscardArray];
[myDiscardArray removeAllObjects];
}
// update player's new position
playerNode.position = CGPointMake(playerNode.position.x+xIncrement, playerNode.position.y+yIncrement);
// check if player has arrived at destination
if(((int)playerNode.position.x == (int)destinationPoint.x) && ((int)playerNode.position.y == (int)destinationPoint.y)) {
working = false;
}
}
}
@end
关于opengl-es - Spritekit 和 OpenGL : smooth smoke trail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29137947/
这个问题在这里已经有了答案: 8年前关闭。 Possible Duplicate: What is a smoke testing and what will it do for me? 为什么“冒烟
我以为我理解烟雾服务器用于持续集成来衡量项目的性能和测试覆盖率。这基本上是正确的吗?对程序进行冒烟测试意味着什么?它是否仅仅意味着持续应用烟雾服务器上定义的测试,以便能够查明特定时间范围内的性能下降情
我无法得到 Smoke 的内容是。我一直期待smoke 会为C++ 代码生成C 包装器,并使用生成的函数创建头文件。 但运行 smokegen在 C++ header 上给了我很小的 header ,
我在网页上使用了一些 core-ajax-dart 元素。自定义事件触发似乎已损坏。当使用声明式 on-core-response="{{ajaxNewProjectResponse}}" 时,该元素
好的,所以我正在使用这个 CodePen 中的脚本: var smokemachine = function(context, color) { color = color || [245, 46
我正在使用 cypress-each 运行动态测试,但总体测试数量很大,我想使用 cypress-grep 将 @smoke 标签添加到数据中,并运行一小部分测试。 如何添加标签 const titl
Аfter将Dart代码(使用Dart Polymer)编译为JS。我收到以下错误: Uncaught Exception: The "smoke" library has not been conf
我最近正在阅读 Wikpedia's list of Anti-Patterns 并注意到这包括在内: Smoke and mirrors: Demonstrating how unimplement
考虑这段代码: class Foo { List listOfStrings; } 使用 smoke包,如何通过查看 listOfStrings 获取 String ? 我看到我们可以从 Type
此代码和动画在 jQuery 1.4.4 及以下版本上完美运行,但在更高版本上无法正常运行。任何人都可以阐明这个问题并帮助开发一个适用于最新 jQuery 的版本。我在下面提供了一个 fiddle 。
使用 testcafe grep 模式可以部分解决我们使用标签的问题,但它仍然会在规范报告中显示这些标签...!!! 有没有办法在测试/夹具名称中包含标签并使用 grep 模式但跳过这些标签以显示在执
好的,所以我有一个列表 nav 可以导航到带有旋转木马幻灯片的某个幻灯片,smoke.js 在访问该站点时加载并自动启动,这正是我想要的,但是当他们单击“主页”按钮以外的任何 nav 按钮,我需要它来
我正在尝试对基于 NEST 的恒温器和 SMOKE CO 探测器进行一些分析。如何在不购买设备的情况下获取温度记录、湿度等样本数据,寻找具有一些虚拟客户详细信息的样本数据集。 如果不是至少是虚拟设备的
我想在我的 Spritekit 游戏中实现这种效果,其中角色后面有一条平滑轨迹。 在喷气背包兜风中查看硬币背后的踪迹: 木星跳跃中英雄背后的这条踪迹: 或者《Ski Safari》中英雄身后的这条 s
我想渲染 3D 体积数据:密度(可以映射到 Alpha channel )、温度(可以映射到 RGB)。目前我正在模拟最大强度投影,例如:最后渲染最密集/不透明的像素。但是这种方法失去了深度感知。 我
我是一名优秀的程序员,十分优秀!