我有几个级别都使用相同的声音效果.我没有在每个级别使用相同的代码,而是将所有声音合并为单个类.但是,当我从其他类中运行该方法时,将它放在单例中没有播放声音.我没有错误或警告.
当我在每个班级都有相同的代码时,播放声音没有问题.
问题:SKAction playSoundFileNamed从单例调用时是不起作用还是我的代码丢失了什么?
我的单例头文件......
-(void)soundSwordWhoosh;
Run Code Online (Sandbox Code Playgroud)
我的单例方法文件......
@implementation Animations{
SKAction *swordWhooshSound;
}
-(id)init {
self = [super init];
if (self)
{
swordWhooshSound = [SKAction playSoundFileNamed:@"SwordWhoosh.mp3" waitForCompletion:YES];
}
return self;
}
-(void)soundSwordWhoosh {
[self runAction:swordWhooshSound];
}
Run Code Online (Sandbox Code Playgroud)
然后我调用这样的方法:
[_animations soundSwordWhoosh];
Run Code Online (Sandbox Code Playgroud) 我刚刚完成了我最新的iPhone应用程序,当我在iPad上测试时遇到了问题.模拟器上每秒的默认帧数为30,但在我的设备上它的大约54到60.这对我来说是一个主要问题,因为我的游戏是一个无限的跑步者并且以我测试的fps的两倍移动使得背景和敌人飞到目前为止太快了.我不能放慢速度,所以我想知道是否可以将fps限制为30.
刚开始用积木工作......非常困惑.我正在使用这样的块:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *myDictionary = [[mySingleton arrayPeopleAroundMe] objectAtIndex:indexPath.row];
NSMutableString *myString = [[NSMutableString alloc] initWithString:@"http://www.domain.com/4DACTION/PP_profileDetail/"];
[myString appendString:[myDictionary objectForKey:@"userID"]];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[myString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection
sendAsynchronousRequest:urlRequest
queue:queue
completionHandler: ^( NSURLResponse *response,
NSData *data,
NSError *error)
{
[[mySingleton dictionaryUserDetail] removeAllObjects];
[[mySingleton arrayUserDetail] removeAllObjects];
if ([data length] > 0 && error == nil) // no error and received data back
{
NSError* error;
NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions …Run Code Online (Sandbox Code Playgroud) 我正在使用 SpriteKit 和 swift 编写一个等距游戏,但我在为我的羊绘制精灵时遇到了麻烦。他们有一个基本的人工智能,可以随机移动它们,但当它绘制时,我得到两条大的黑色水平线,而不是一只羊。我正在使用 init(rect:inTexture:) 获取精灵表的第一个子图像。我只做一只羊来测试我的代码。这是我的代码:
//
// Animal.swift
// Anointed
//
// Created by Jacob Jackson on 4/26/15.
// Copyright (c) 2015 ThinkMac Innovations. All rights reserved.
//
import Foundation
import SpriteKit
/* DEFINES AN ANIMAL */
class Animal : SKSpriteNode {
let animalName: String //name
let descript: String //description
let spriteSheetName: String //image name for item icon
var deltaT = 0.0
var startTime = 0.0
init( name: String, desc: String, sheetName: String ) {
animalName = name …Run Code Online (Sandbox Code Playgroud) 我在 SKScene 中有一个节点,我根据用户的触摸来移动它。基本上,这个角色还应该尝试跟随用户的手指(假设手指在屏幕上)。我目前已经这样实现了,效果很好:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1))
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
let touch = touches.first as! UITouch
player.runAction(SKAction.moveTo(touch.locationInNode(self), duration: 1))
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
player.removeAllActions()
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
player.removeAllActions()
}
Run Code Online (Sandbox Code Playgroud)
然而,问题是如果用户将手指放在手机上。TouchesBegan 仅被调用一次,即点击开始时,而不是按住时。我希望玩家角色不断地尝试到达手指。
我将相机集中在节点上,因此节点应该触摸手指的唯一时间是用户将手指放在节点上/节点内(即与节点相同的位置)。因此,在我运行 SKAction 来移动节点后,触摸无效,因为它位于旧位置。
我该怎么做?
我通过在 Xcode 中使用 Storyboards 引用自定义来创建 SpriteKit 场景NSView。但是,我无法mouseMoved使用 SpriteKit 实现任何事件,因为我不知道如何引用程序NSWindow将其属性设置acceptsMouseMovedEvents为“true”。
如何在我的文件中创建@IBOutlet对 my 的引用,以便更改此属性?NSWindowAppDelegate.swift
sprite-kit ×5
ios ×3
swift ×3
cocoa ×1
frame-rate ×1
iboutlet ×1
iphone ×1
macos ×1
singleton ×1
skaction ×1