我正在阅读有关Unity JS的文章.文章展示了一个统一js类的例子.
class Person{
var name;
var career;
}
//Create objects of type Person
var john = Person();
john.name = "John Smith";
john.career = "doctor";
Debug.Log(john.name + " is a " + john.career);
Run Code Online (Sandbox Code Playgroud)
看起来Unity JS实际上支持class关键字.它如何支持classJavaScript?他们使用的是死ES4规格还是修改过的ES3或5?
我有一个自动合成readonly及weak性质:
@property (nonatomic, readonly, weak) KTWindowController* windowController;
Run Code Online (Sandbox Code Playgroud)
我分配合成的ivar,然后将其添加到一个数组:
_windowController = [KTWindowController controller];
[self addSubController:_windowController];
Run Code Online (Sandbox Code Playgroud)
这在Debug构建中工作正常.但我得到一个报告,在发布(ad hoc)构建中,这将立即为nil _windowController然后它尝试将nil添加到数组,从而使应用程序崩溃.
与Debug版本相比,发布(ad hoc)版本中的哪些特定设置(优化级别?)会改变此行为?
令我感到奇怪的是,这种行为将从Debug版本变为Release版本.但我能够重现这种行为,它实际上是有意义的 - 只是当它与调试版本中发生的事情不一致时.
建议的解决方法:
KTWindowController* windowController = [KTWindowController controller];
[self addSubController:windowController];
_windowController = windowController;
Run Code Online (Sandbox Code Playgroud)
除了使用如上所示的局部变量之外,在这样的情况下,您会推荐哪种解决方法?
真的很快问题(我可以自己测试,但不能在带Xcode的计算机上测试):
如果ARC将弱属性设置为nil,属性的setter是否会以参数nil运行,或者在这种情况下绕过属性setter?
properties weak-references objective-c automatic-ref-counting
我必须在类(不是实例)上按名称执行选择器并使用其返回值:
id obj = [objClass performSelector:NSSelectorFromString(methodName) withObject:p1];
Run Code Online (Sandbox Code Playgroud)
选择器创建Class的新实例.我需要使用返回的实例.显然,我得到通常的performSelector可能会导致泄漏,因为它的选择器是未知的警告,因为这个项目是用ARC编译的.
如果我理解正确(从这里和其他人的答案),在这个实例中,performSelector 将导致泄漏(如果我错了,请纠正我,然后我可以禁用警告并完成它).选择器实现如下:
+ (id) objectWithFile:(NSString*)p1
{
return [NSKeyedUnarchiver unarchiveObjectWithFile:p1];
}
Run Code Online (Sandbox Code Playgroud)
当我必须从字符串使用选择器并且选择器创建并返回对象的新实例时,我有什么选择?
我考虑过NSInvocation但是它的getReturnValue方法要求我提供我自己分配的缓冲区,其中存储了返回值.我不确定这是否适用于ARC和类方法,或者我是否只需要将__bridge_transfermalloc的返回值缓冲区转换为,id并且这就是它的全部内容.
memory-leaks objective-c automatic-ref-counting performselector
我试图在Cocos2d-x中移植像素完美碰撞检测,原始版本是为Cocos2D制作的,可以在这里找到:http://www.cocos2d-iphone.org/forums/topic/pixel-perfect-collision-detection -使用色混/
这是我的Cocos2d-x版本的代码
bool CollisionDetection::areTheSpritesColliding(cocos2d::CCSprite *spr1, cocos2d::CCSprite *spr2, bool pp, CCRenderTexture* _rt) {
bool isColliding = false;
CCRect intersection;
CCRect r1 = spr1->boundingBox();
CCRect r2 = spr2->boundingBox();
intersection = CCRectMake(fmax(r1.getMinX(),r2.getMinX()), fmax( r1.getMinY(), r2.getMinY()) ,0,0);
intersection.size.width = fmin(r1.getMaxX(), r2.getMaxX() - intersection.getMinX());
intersection.size.height = fmin(r1.getMaxY(), r2.getMaxY() - intersection.getMinY());
// Look for simple bounding box collision
if ( (intersection.size.width>0) && (intersection.size.height>0) ) {
// If we're not checking for pixel perfect collisions, return true
if (!pp) … 我想将网格物体切成至少五个部分.我做了一些研究,这里的一些人在切片时克隆了对象,只是从一个切片中实例化了两个对象?
我是Unity和C#的新手.所以任何关于从哪里开始或者我可以阅读以学习如何切割网格的初学者教程都会很好.我应该研究哪些功能/方法?切割网格背后的方法是什么?
根据我的理解,我还没有看到任何实际削减三角形网格的教程或资产?如果有,怎么办?它背后的逻辑是什么?我想我需要帮助理解它背后的逻辑以及如何开始或我应该研究什么?
我的意思是实时剪切网格.
编辑:
尝试理解并玩弄代码:
我使用了假切片机3.0(http://unitycoder.com/blog/2011/08/09/fake-mesh-slicer-v3-0/)并包含在样本中,它们有一个切片机可以使用的胶囊.
如果我添加了具有刚体属性和碰撞器属性的立方体或另一个胶囊,则切片器(也称为平面)仅克隆对象并且不会将其切掉.这是为什么?如何操作上面的代码来处理各种对象?
我收到此控制台错误,我不知道这意味着什么:
UnasssignedReferenceException: The variable cutplane of 'Slice_mesh3_js' has not been assigned. You probably need to assign the cutplane variable of the Slice_mesh3_js script in the inspector.
Run Code Online (Sandbox Code Playgroud) 我正在制作一个"菜单",其中SKNode是菜单背景,还有一堆SKSpriteNodes作为子元素选项.
问题是我无法弄清楚如何向SKNode添加颜色或纹理或其他东西作为菜单的背景; 没有.size,.texture,.color或.background/.backgroundcolor方法选项
我应该在内部使用SKSpriteNode与其他SKSpriteNode,还是应该在内部使用SKScene而不是SKSpriteNodes?或者有没有办法为SKNode分配背景图像或颜色?
我已经google了很多,只提出了非常复杂的方法.我还发现函数OnMouseDown()但我无法使其工作.
当你点击屏幕上的任何地方时,精灵激活.
编辑 - 是的它有一个2d Box对撞机
我的代码如下:
using UnityEngine;
using System.Collections;
public class mute : MonoBehaviour {
public bool isMuted = false;
public Sprite mute1; // Drag your first sprite here
public Sprite mute2; // Drag your second sprite here
private SpriteRenderer spriteRenderer;
// Use this for initialization
void Start () {
spriteRenderer = GetComponent<SpriteRenderer>(); // we are accessing the SpriteRenderer that is attached to the Gameobject
if (spriteRenderer.sprite == null) // if the sprite on spriteRenderer is …Run Code Online (Sandbox Code Playgroud) 我已经安装了cocos2d-x 3.0并尝试构建一个Android版本但是当我运行./build_native.py时,它失败并出现错误
File "./build_native.py", line 89, in do_build
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ /Users/hoangha/Desktop/Enigma/cocos2d-x-3.0/projects/2048-enhanced-version/source/proj.android ] fails!
Run Code Online (Sandbox Code Playgroud)
我已经阅读了build_native.py中的第89行
if os.system(command) != 0:
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Run Code Online (Sandbox Code Playgroud)
但是我不理解python中的命令os.system(命令),所以任何人都可以帮我解决这个错误.
我在斯威夫特做一个游戏.我已经使用了UIKit和SpriteKit,但从未在同一个应用程序中使用过.我想知道如何利用它们的力量(它们将成为很多菜单).如果您知道我可以使用的教程,或者可以告诉我,我会非常感激.我也想知道xcode中是否有这样的快捷方式(例如故事板)
ios ×3
objective-c ×3
c# ×2
cocos2d-x ×2
sprite-kit ×2
swift ×2
unityscript ×2
android ×1
c++ ×1
class ×1
memory-leaks ×1
mesh ×1
properties ×1
python ×1
uikit ×1