public void initWithImageNamed(string imageName) { gameObject.name = imageName; CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache.spriteFrameByName(imageName); if (frame == null) { CCDebug.Info("cocos2d:CC3Sprite: try to load '{0}' as a file.", imageName); string path = FileUtils.GetFilePathWithoutExtends(imageName); Texture2D texture = Resources.Load <Texture2D> (path); NSUtils.Assert(texture != null, "cocos2d:CC3Sprite: '{0}' not found.", path); frame = new CCSpriteFrame(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height))); frame.semiTransparent = false; } initWithSpriteFrame(frame); }
/** Returns an Sprite Frame that was previously added. * If the name is not found it will return nil. * You should retain the returned copy if you are going to use it. */ public CCSpriteFrame spriteFrameByName(string name) { CCSpriteFrame frame = _spriteFrames [name]; if (frame == null) { // try alias dictionary string key = _spriteFramesAliases[name]; if (key != null) { frame = _spriteFrames [key]; } if (frame == null) { CCDebug.Info("cocos2d: CCSpriteFrameCache: Frame '{0}' not found", name); } } return(frame); }