小编Dar*_*das的帖子

在swift中,如何在删除SKScene后让内存恢复正常?

我使用SpriteKit创建了一个简单的游戏,但是每次运行游戏时,模拟器中的内存使用量增加约30mb,但在游戏结束时不会减少.

当我运行游戏超过十次时,模拟器变得越来越慢并最终崩溃.

在这个简单的游戏中,我有两个控制器和一个gamecene:

MainController通过触发按钮调用GameViewController

在GameViewController中,gamescene以这种方式初始化:

class GameViewController: UIViewController
{

  var skView:SKView!

  var scene:GameScene!

  override func viewDidLoad() {

      super.viewDidLoad()
      scene = GameScene(size: view.bounds.size)
      skView = view as SKView
      skView.ignoresSiblingOrder = true
      scene.scaleMode = .ResizeFill

      scene.viewController = self
      skView.presentScene(scene)

  }

//with a prepareForSegue deinitialises the scene and skview:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if segue.identifier == "GameFinished"{

        scene.removeAllActions()
        scene.removeAllChildren()
        scene.removeFromParent()
        scene = nil

        skView.presentScene(nil)
        skView = nil

        let target = segue.destinationViewController as MainController
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在GameScene中,viewController是一个属性

var viewController:GameViewController? = …
Run Code Online (Sandbox Code Playgroud)

memory sprite-kit skscene swift

12
推荐指数
1
解决办法
2573
查看次数

authenticateWithCompletionHandler:不推荐使用:首先在iOS 6.0中弃用

我正在开发使用Game Center的游戏,然后我得到下一个警告;

...'authenticateWithCompletionHandler:'已弃用:首先在iOS 6.0中弃用

好的,我搜索并发现有新的代码用于验证本地用户,所以我更换了

旧代码:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");
    if ([GKLocalPlayer localPlayer].authenticated == NO) {
        [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
    } else {
        NSLog(@"Already authenticated!");
    }
}
Run Code Online (Sandbox Code Playgroud)

用新的:

- (void)authenticateLocalUser {

    if (!gameCenterAvailable) return;

    NSLog(@"Authenticating local user...");

    if ([GKLocalPlayer localPlayer].authenticated == NO) {

        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
        //[localPlayer authenticateWithCompletionHandler:^(NSError *error) { OLD CODE!
            if(localPlayer.isAuthenticated) {
                //do some stuff
            }else {
                // not logged in   
            }
        })]; 
    } else { …
Run Code Online (Sandbox Code Playgroud)

iphone ios game-center

7
推荐指数
1
解决办法
7723
查看次数

Cocos2d-x安装的应用程序无法在android上启动

我使用的开发的游戏cocos2d-x,我成功地打它iOS,MacOSwin32而此刻我有问题,尝试启动它在Android上.编译和安装完成我无法启动它因为我无法理解/看到的问题.有人可以帮忙或暗示我这个问题吗?

信息:在真实设备上测试,Android版本4.4.4.,cocos2d-x-3.13.1,c ++,目标4.4.2,eclipse Neon.1a版本(4.6.1),mac os.

如果需要其他信息,我可以提供.

AndroidManifest.xml中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.companyName.gameName"
  android:versionCode="1"
  android:versionName="1.0"
  android:installLocation="auto">

<uses-sdk android:minSdkVersion="19"/>
<uses-feature android:glEsVersion="0x00020000" />

<application android:label="@string/app_name"
             android:icon="@drawable/icon">

    <!-- Tell Cocos2dxActivity the name of our .so -->
    <meta-data android:name="android.app.lib_name"
               android:value="MyGame" />

    <activity android:name="org.cocos2dx.cpp.AppActivity"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
              android:configChanges="orientation|keyboardHidden|screenSize">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<supports-screens android:anyDensity="true"
                  android:smallScreens="true"
                  android:normalScreens="true"
                  android:largeScreens="true"
                  android:xlargeScreens="true"/>

<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" android:protectionLevel="signature"/>
Run Code Online (Sandbox Code Playgroud)

LogCat(警告,错误,断言):

04-21 09:49:49.917: E/Watchdog(596): !@Sync 1245
04-21 09:49:52.780: …
Run Code Online (Sandbox Code Playgroud)

eclipse android cocos2d-x

5
推荐指数
1
解决办法
279
查看次数

Objective-C:如何将参数传递给方法

int land4Random = arc4random_uniform(3);
if (land4Random == 0)
{
    Land4.image = [UIImage imageNamed: @"GoodLandBR.jpg"];
}
if (land4Random == 1)
{
    Land4.image = [UIImage imageNamed: @"DeadLand.jpg"];
}
Run Code Online (Sandbox Code Playgroud)

我想多次使用这段代码,但我不知道如何制作它的方法。

objective-c ios

-2
推荐指数
1
解决办法
1367
查看次数