小编tha*_*guy的帖子

检测sprite工具包中的碰撞

我正在尝试用精灵套件制作一个简单的游戏.基本的想法是有一个玩家可以跳跃以避免阻挡.但我有一个问题我不知道怎么做,当玩家击中阻止时,玩家消失并且血液动画开始.首先,我不明白我在苹果网站上找到的代码是什么.

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)

objective-c collision ios sprite-kit

15
推荐指数
2
解决办法
2万
查看次数

c ++构造函数不工作

这是我的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)

c++ constructor class

3
推荐指数
1
解决办法
3422
查看次数

Lua碰撞零值

当我尝试执行以下代码时,它给了我这个错误:

尝试索引字段'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)

提前致谢 :)

null lua physics collision

0
推荐指数
1
解决办法
129
查看次数

标签 统计

collision ×2

c++ ×1

class ×1

constructor ×1

ios ×1

lua ×1

null ×1

objective-c ×1

physics ×1

sprite-kit ×1