我在游戏中遇到了奇怪的行为。我有一个SKSpriteNode
。在force
SKSpriteNode
force
SKSpriteNode
开始旅行(即mySpriteNode.physicsBody.isResting == NO
)之后,mySpriteNode.physicsBody.isResting == YES
给了position
。
情景:
当球停止它的模拟(即mySpriteNode..physicsBody.isResting == NO
)并且我向mySpriteNode提供任何velocity
。这很有效。
,但
当mySpriteNode正在旅行时(即mySpriteNode..physicsBody.isResting == YES
)并且我将position
0 提供给mySpriteNode并停止(即position
)。但是当我给它任何 #include <iostream>
#include "Lista.h"
#include <stddef.h>
using namespace std;
void insert(){
Lista l;
inserimento->next = NULL;
cout<<"inserisci elemento"<<"\n";
cin>>inserimento->num;
if(testa==NULL){
inserimento->next=NULL;
testa=inserimento;
}
else
{
if(testa->num > inserimento->num) //insert on head
{
inserimento->next = testa;
testa = inserimento;
}
else
{
temp = testa;
while(temp->next != NULL && temp->next->num < inserimento->num)
temp = temp->next;
if(temp->next == NULL) //insert on least
{
temp->next = inserimento;
}
else //insert between
{
inserimento->next = temp->next;
temp->next = inserimento;
}
}
}
}
时,它没有任何效果。
mySpriteNode&#39; s #ifndef LISTA_H_
#define LISTA_H_
#include <stddef.h>
namespace std{
class Lista {
public:
struct nodo{
struct node *next ;
int num ;
};
nodo *temp = NULL;
nodo *testa = NULL;
nodo *inserimento = NULL;
void insert(nodo);
};
}
#endif /* LISTA_H_ */
仍然是我给出0速度的地方。
有什么想法吗?
答案 0 :(得分:-1)
当我在动作块完成中重新定位精灵时,它对我来说非常合适。
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Spaceship"];
sprite.xScale = 0.5;
sprite.yScale = 0.5;
sprite.position = CGPointMake(self.size.width/2.0, self.size.height/2.0);
sprite.physicsBody = [ SKPhysicsBody bodyWithRectangleOfSize:sprite.size];
SKAction *act1 = [SKAction runBlock:^{
[sprite.physicsBody applyImpulse:CGVectorMake(0, 100)];
}];
SKAction *act2 = [SKAction waitForDuration:2];
SKAction *act3 = [SKAction runBlock:^{
[sprite.physicsBody setVelocity:CGVectorMake(0, 0)];
}];
SKAction *seq = [SKAction sequence:@[act1,act2,act3]];
[sprite runAction:seq completion:^{
sprite.position = CGPointMake(self.size.width/2.0, self.size.height/2.0);
}];
self.physicsWorld.gravity = CGVectorMake(0, 0);
尝试在动作的完成块中重新定位。