我正在尝试用精灵套件制作一个简单的游戏.基本的想法是有一个玩家可以跳跃以避免阻挡.但我有一个问题我不知道怎么做,当玩家击中阻止时,玩家消失并且血液动画开始.首先,我不明白我在苹果网站上找到的代码是什么.
static const uint32_t blockCategory = 0x1 <<0;
static const uint32_t playerCategory = 0x1 <<1;
Run Code Online (Sandbox Code Playgroud)
比我调用didBeginContact函数并在其中放置一个NSLOG("确实调用函数").但我从来没有在调试器中收到输出.
这是我的_player和_block代码: - (SKSpriteNode*)character {
_player = [SKSpriteNode spriteNodeWithImageNamed:@"soldier_run1"];
_player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:_player.size.width /2 -5];
_player.physicsBody.dynamic = YES;
_player.physicsBody.usesPreciseCollisionDetection = YES;
_player.physicsBody.friction = 0;
_player.physicsBody.categoryBitMask = playerCategory;
_player.physicsBody.collisionBitMask = blokCategory;
_player.name = @"player";
SKAction *animAction = [SKAction animateWithTextures:playerTextures timePerFrame:0.1 resize:YES restore:YES];
Run Code Online (Sandbox Code Playgroud)
我的_player代码:
[_player runAction:[SKAction repeatActionForever:animAction]];
return _player;
}
-(SKSpriteNode *)block {
_blok = [[SKSpriteNode alloc] initWithColor:[SKColor blackColor] size:CGSizeMake(15, 40)];
//physics
_blok.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_blok.size];
_blok.physicsBody.dynamic …Run Code Online (Sandbox Code Playgroud) 这是我的makeAccount.cpp:
#include "account.h"
#include <string>
using namespace std;
int makeAccount::getAccountNumber()
{
return accountNumber;
}
double makeAccount::getAccountSaldo()
{
return accountSaldo;
}
string makeAccount::getName()
{
return name;
}
makeAccount::makeAccount(std::string naam, int id, double saldo)
{
naam = name;
id = accountNumber;
saldo = accountSaldo;
}
Run Code Online (Sandbox Code Playgroud)
这是我的makeAccount.h
#include <string>
#include <sstream>
class makeAccount
{
public:
makeAccount(std::string naam, int id, double saldo);
int getAccountNumber();
double getAccountSaldo();
std::string getName();
private:
int accountNumber;
double accountSaldo;
std::string name;
};
Run Code Online (Sandbox Code Playgroud)
这是我的main.cpp
#include "account.h"
#include <iostream>
using namespace std; …Run Code Online (Sandbox Code Playgroud) 当我尝试执行以下代码时,它给了我这个错误:
尝试索引字段'other'(零值)
但我不知道为什么.
代码:
function onCollision(event)
if event.phase == "began" then
if event.other.star == "star" then
score = score + 1
elseif event.other.mine1 == "mine1" then
if jet.collided == false then
timer.cancel(tmr)
jet.collided = true
jet.bodyType = "static"
explode()
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
提前致谢 :)
collision ×2
c++ ×1
class ×1
constructor ×1
ios ×1
lua ×1
null ×1
objective-c ×1
physics ×1
sprite-kit ×1