小编Lea*_*s2D的帖子

Unity3d从Textures文件夹加载精灵

我有大约200小精灵(JPG图片)Assets>Textures>Pictures,我也GameObject有<SpriteRenderer>.有没有办法让我GameObject在代码中从该文件夹加载sprite ?就像是Resources.Load<Sprite>("path");

谢谢.

sprite unity-game-engine unityscript

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

SKSpriteNode子类化swift

我已经找到了一些帖子,但我仍然对如何做到这一点感到困惑.我知道我必须使用"指定的初始化程序",它是init(纹理:SKTexture!,颜色:UIColor!,大小:CGSize).真的,我还是不会用它.我想向sprite节点添加一些属性.

class Piece: SKSpriteNode {

enum Type: Int {
    case type1 = 1, type2, type3, type4, type5
}

    var piecetype : Type 

init(texture: SKTexture!, color: UIColor!, size: CGSize)
{
    self.piecetype = .type1
    super.init(texture: texture, color: color, size: size)

}


convenience init(imageNamed: String!, currentPiece: Type)
    {
        self.piecetype = currentPiece
        let color = UIColor()
        let texture = SKTexture(imageNamed: imageNamed)
        let size = CGSizeMake(100.0, 100.0)
        super.init(texture: texture, color: color, size: size)
    }
Run Code Online (Sandbox Code Playgroud)

在主要代码中我尝试使用添加一块

var newPiece : Piece = Piece(imageNamed: "image.png", currentPiece: .type1)
self.addChild(newPiece) …
Run Code Online (Sandbox Code Playgroud)

initialization ios sprite-kit skspritenode swift

4
推荐指数
1
解决办法
4999
查看次数

在SKScene中使用UIViewController

在我的GameScene.swift文件中,我正在尝试将segue执行回我的菜单视图控制器,如下所示:

func returnToMainMenu(){
    var vc: UIViewController = UIViewController()
    vc = self.view!.window!.rootViewController!
    vc.performSegueWithIdentifier("menu", sender: vc)
}
Run Code Online (Sandbox Code Playgroud)

点击节点时会运行此方法:

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)
        if gameOn == false{
            if restartBack.containsPoint(location){
                self.restartGame()
            }
            else if menuBack.containsPoint(location){
                self.returnToMainMenu()
            }
            else if justBegin == true{
                self.restartGame()
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

哪里menuBack是按钮返回菜单.每次运行此代码时,都会抛出NSException:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ProxyBlock.Menu: 0x165a3e90>) has no segue with identifier 'menu''
Run Code Online (Sandbox Code Playgroud)

我检查了我的segue的标识符,它确实是"菜单".

ios segue sprite-kit swift

4
推荐指数
1
解决办法
5028
查看次数

触发器激活后如何等待5秒钟?

我试图在触发器满足后等待五秒钟,然后在五秒钟后我想要进入下一个场景.问题是一旦触发得到满足,它就会自动进入下一个场景.

我试过了什么

using UnityEngine;
using System.Collections;

public class DestroyerScript : MonoBehaviour {


IEnumerator WaitAndDie()
{
    yield return new WaitForSeconds(5);

}
void Update()
{

        StartCoroutine(WaitAndDie());         

}
void OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "Player") 
    {
        Update();     
        Application.LoadLevel("GameOverScene");
        return;
    }

}
}
Run Code Online (Sandbox Code Playgroud)

我也试过了

using UnityEngine;
using System.Collections;

public class DestroyerScript : MonoBehaviour {


IEnumerator WaitAndDie()
{
    yield return new WaitForSeconds(5);

}

void OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "Player") 
    {
        StartCoroutine(WaitAndDie());         
        Application.LoadLevel("GameOverScene");
        return;
    }

}
}
Run Code Online (Sandbox Code Playgroud)

c# triggers unity-game-engine

4
推荐指数
1
解决办法
1239
查看次数

是否有可能为身体创造一个可被其他身体打破的固定装置?

我真的想知道,是否有可能为身体创造一个可以被其他身体打破的装置?

有一个例子:

  • 一个身体,其夹具分为小图:
  • 在被另一个机构击中后会发生什么:

Ps是否有任何程序可以帮助创建这样的夹具的过程?

fixtures box2d libgdx

4
推荐指数
1
解决办法
798
查看次数

如何为重力设置不同的值?

我在Xcode中使用Sprite Kit,我想更改在重力上设置的默认值.这是我的代码:

SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"sprite1.png"];
        sprite.position = CGPointMake(-100+CGRectGetMidX(self.frame), 50 + CGRectGetMidY(self.frame));
        [self addChild:sprite];
        sprite.color = [SKColor blueColor];
        sprite.colorBlendFactor = 1.0;
        sprite.xScale = 0.2;
        sprite.yScale = 0.2;
        [SKPhysicsBody bodyWithCircleOfRadius:50];
        sprite.physicsBody.dynamic = YES;
        sprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width * 0.5];
Run Code Online (Sandbox Code Playgroud)

现在我知道使用这行代码应该提供默认设置但我现在无法运行项目:

//self.physicsWorld.gravity = CGPointMake(0.0, -9.8);
Run Code Online (Sandbox Code Playgroud)

救命?

physics gravity sprite-kit skphysicsbody

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

如何检测sprite kit中的碰撞?

我在Sprite Kit中制作游戏,我在SpriteNodes之间的碰撞检测方面遇到了困难,我设置了一个名为sprite的sprite节点和一个名为platform的sprite节点.我希望精灵在与平台相撞时停止下降.这就是我所拥有的:

        SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bal.png"];
        sprite.position = CGPointMake(self.frame.size.width/4 + arc4random() % ((int)self.frame.size.width/2), (self.frame.size.height/2 + arc4random() % ((int)self.frame.size.height/2)));
        sprite.color = [self randomColor];
        sprite.colorBlendFactor = 1.0;
        sprite.xScale = 0.2;
        sprite.yScale = 0.2;
        [self addChild:sprite];
        sprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.size.width/2];
        self.physicsWorld.gravity = CGVectorMake(0.0f, -4.0f);

        SKSpriteNode *platform = [SKSpriteNode spriteNodeWithImageNamed:@"YellowPlatform.png"];
        platform.position = CGPointMake(CGRectGetMidX(self.frame), -200+CGRectGetMidY(self.frame));
        platform.size = CGSizeMake(180, 10);
        [self addChild:platform];
Run Code Online (Sandbox Code Playgroud)

提前致谢!

collections sprite-kit skphysicsbody

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

cocos2d-x仅在eclipse中出现纯虚方法错误

我正在关注一本韩国cocos2d-x书籍,并且编写了示例代码并在xcode和ios中运行良好.

但eclipse抱怨纯虚方法(代码完全相同!)

以下是错误消息.

"GameObject"类型必须实现继承的纯虚方法'cocos2d :: CCRGBAProtocol :: setOpacity'

class GameObject : public CCSprite

代码没什么特别的.定义GameObject类并从CCSprite继承.

我认为没有必要使用CCRGBAProtocol或setOpacity.为什么日食会抱怨这个?

提前致谢.

(cocos2d-x版本为2.2,android项目文件由cocos2d-x默认脚本生成)

eclipse android cocos2d-x

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

SKAction playSoundFileNamed通过iphone扬声器没有音频

有没有人通过iOS设备的外部扬声器使用iOS Sprite Kit通过SKAction playSoundFileNamed播放音频有问题?我有以下代码播放M4A文件没有问题通过耳机; 但是,当我拔下耳机时,没有播放音频,单步执行没有声音的代码.我有另一个不使用此方法的应用程序,它没有问题.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];
        SKAction *sound = [SKAction playSoundFileNamed:@"blast.m4a" waitForCompletion:NO];
        [self runAction:sound];
 }
Run Code Online (Sandbox Code Playgroud)

iphone audio ios sprite-kit skaction

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

调整SKShapeNode的大小

如何调整SKShapeNode的大小?

到目前为止我尝试过的:

帧大小调整

box.frame.width = 10

给出错误 Cannot assign to the result of this expression

SKAction

let actionResize = SKAction.resizeToWidth(10, duration: NSTimeInterval(0.1))
box.runAction(actionResize)
Run Code Online (Sandbox Code Playgroud)

什么都没发生

xScale等

box.xScale = 0.1

缩放节点而不是调整大小

resize ios sprite-kit skshapenode swift

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