本文的目的是介绍iphone–在iOS中使用Cocoa在后台进行9切缩缩放/拉伸的详细情况,特别关注ios启用缩放的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解ip
本文的目的是介绍iphone – 在iOS中使用Cocoa在后台进行9切缩缩放/拉伸的详细情况,特别关注ios启用缩放的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解iphone – 在iOS中使用Cocoa在后台进行9切缩缩放/拉伸的机会,同时也不会遗漏关于cocoa ios iphone xcode 播放GIF动画、cocos2d-iphone – Cocos2d iPhone – Sprite cliping / mask / frame、cocos2d-iphone – 使用cocos2d游戏的状态设计模式、cocos2d-iphone – 用Cocos2d进行UIAutomation测试,可能吗?的知识。
本文目录一览:- iphone – 在iOS中使用Cocoa在后台进行9切缩缩放/拉伸(ios启用缩放)
- cocoa ios iphone xcode 播放GIF动画
- cocos2d-iphone – Cocos2d iPhone – Sprite cliping / mask / frame
- cocos2d-iphone – 使用cocos2d游戏的状态设计模式
- cocos2d-iphone – 用Cocos2d进行UIAutomation测试,可能吗?
iphone – 在iOS中使用Cocoa在后台进行9切缩缩放/拉伸(ios启用缩放)
stretchableImageWithLeftCapWidth
方法,但我想在后台线程中这样做.据我所知,这个方法只能在gui线程中使用.
我正在开发iOS / iPad / iPhone.
有没有人有代码片段,或者知道可以执行此操作的库?我正试图不重新发明轮子!
我发现一些有用的参考资料:
CGContext文档:
> http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
关于在后台绘图的好博客条目:
> http://joris.kluivers.nl/iphone-dev/?p=BackgroundImageProcessing
使用CGContext旋转图像:
> http://blog.coriolis.ch/2009/09/04/arbitrary-rotation-of-a-cgimage/
解决方法
如果你需要支持iOS 3,那就有点困难了.如果你想完全避免UIKit(可能是明智的),那么你需要将后台线程传递给CGImageRef.还有一些你可能需要担心的事情;我假设比例是1而imageOrientation是肖像.
>创建上下文:CGBitmapContextCreate()
>创建子图像:CGImageCreateWithImageInRect().
>将每个子图像绘制到正确的位置:CGContextDrawImage()
>从上下文中获取图像:CGBitmapContextCreateImage()
>释放必要的东西并将CGImageRef返回到主线程.
>在主线程中,使用[UIImage imageWithCGImage:]或imageWithCGImage:scale:orientation :(请注意,在后一种情况下,带有比例2的图像似乎只支持纵向方向;我不确定为什么).
另请注意,将图像粘贴在UIImageView中并适当设置contentStretch会更好,因为此时缩放是在GPU上完成的.
cocoa ios iphone xcode 播放GIF动画
使用imageio的这个自带的framework,这个库也是apple的webkit所使用的,可以参考apple的opensource的webkit实现。 因此,这个 库从性能和蒹容性方面应该都是最佳选择
以下是代码,比较简单
NSDictionary *gifLoopCount = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:0],(Nsstring *)kCGImagePropertyGIFLoopCount,nil ]; NSDictionary * gifProperties = [NSDictionary dictionaryWithObject:gifLoopCount forKey:(Nsstring *)kCGImagePropertyGIFDictionary] ; CGImageSourceRef gif = CGImageSourceCreateWithData((__bridge CFDataRef)(data),(__bridge CFDictionaryRef)gifProperties); CFDictionaryRef gifprops =(CGImageSourcecopyPropertiesAtIndex(gif,NULL)); NSInteger count =CGImageSourceGetCount(gif); CFDictionaryRef gifDic = CFDictionaryGetValue(gifprops,kCGImagePropertyGIFDictionary);//[gifprops objectForKey:(Nsstring *)kCGImagePropertyGIFDictionary]; NSNumber * delay = CFDictionaryGetValue(gifDic,kCGImagePropertyGIFDelayTime); //[gifDic objectForKey:(Nsstring *)kCGImagePropertyGIFDelayTime]; NSNumber * w = CFDictionaryGetValue(gifprops,@"PixelWidth"); NSNumber * h =CFDictionaryGetValue(gifprops,@"PixelHeight"); totalDuration = delay.doubleValue * count; pixelWidth = w.intValue; pixelHeight = h.intValue; images = [[NSMutableArray alloc] init]; for(int index=0;index<count;index++) { CGImageRef ref = CGImageSourceCreateImageAtIndex(gif,index,nil); UIImage *img = [UIImage imageWithCGImage:ref]; [images addobject:img]; CFRelease(ref); } CFRelease(gifprops); CFRelease(gif);
解压完之后,直接用IMageview就可以播放了。代码如下。
UIImageView *image = ....;
image.animationDuration = totalDuration; image.animationImages = images; [image startAnimating]
cocos2d-iphone – Cocos2d iPhone – Sprite cliping / mask / frame
类似的东西:
设置UIView的框架,剪切子视图= TRUE
我的CCSprite Main Sprite添加了多个Child Sprite.
我只想要这个主Sprite Sprite的Mask部分可见.
有没有办法剪辑或使用掩码的CCSprite?
我可以剪下面的背景和层次,只留下可见的区域,但这是唯一的办法吗?
这是一个示例图像,展示了我正在实现的目标:
alt text http://dnamique.com/maskSprite.jpg
在Mainsprite我被压制:
- (void) visit { if (!self.visible) { return; } glEnable(GL_SCISSOR_TEST); glScissor(x,y,width,height); [super visit]; gldisable(GL_SCISSOR_TEST); }
这将剪切或掩蔽指定的区域.
唯一棘手的一点是,在风景模式下,Cocos2D在屏幕左下方有0,而OpenGL在右下角没有它,因为它不考虑屏幕的方向.
换句话说,对于OpenGL,您认为您有一个旋转的肖像画面.
cocos2d-iphone – 使用cocos2d游戏的状态设计模式
如果他们选择单人游戏,那么他们可以选择玩3种不同的模式.
>练习
没有计时器
>压力
玩家必须在10秒内反复进行拼图,直到它在10秒钟内无法完成拼图并且他们“死”
>时间之战
玩家有2分钟可以做尽可能多的谜题.
你知道,实际的游戏玩法并没有改变,但唯一改变的是如何管理时间.
我读了你的文章,我发现State模式非常适合,现在我唯一的问题就是如何实现这种模式.
我应该在菜单状态抽象和游戏抽象中创建子状态,还是应该创建一个通用游戏状态抽象,然后忽略“handleMenuSelection”之类的调用?
我在cocos2d上找不到任何在线报道的好教程.我可以找到很多小型演示,但是除了OOP设计之外,我从未触及过设计模式,因此很难将其转换为大型应用程序.
顺便说一句.你的链接非常有帮助,为新想法开启了我的思想:)
解决方法
示例:说MyGame用于存储所有游戏统计信息.
//在MyGame.h中
typedef enum { kGameMode_Practice = 1001,kGameMode_Stress,kGameMode_TimeBattle,}GameMode; @interface MyGame: NSObject { GameMode mGameMode; int mHighscore; } @property(nonatomic,assign) GameMode gameMode;
@property(nonatomic,assign)int highscore;
+(MyGame*)sharedGameObject;
//在MyGame.mm中
static MyGame *gGame = nil; @implementation MyGame @synthesize gameMode=mGameMode; @synthesize highscore=mHighscore; +(MyGame*)sharedGameObject { if(!gGame) { gGame = [[MyGame alloc] init]; } return gGame; } -(void)saveData //Call this from applicationWillResignActive { NSUserDefaults *userDafs = [NSUserDefaults standardUserDefaults]; [userDafs setInteger:self.highscore forKey:@"highscore"]; [userDafs setInteger:self.gameMode forKey:@"gameMode"]; [[NSUserDefaults standardUserDefaults] synchronize]; } -(void)loadData //call this from UIApplication didFinishLaunchingWithOptions { NSUserDefaults *userDafs = [NSUserDefaults standardUserDefaults]; self.highscore = [userDafs integerForKey:@"highscore"] self.gameMode = (GameMode)[userDafs integerForKey:@"gameMode"] }
//您可以在选择菜单按钮时设置游戏模式
[MyGame sharedGameObject].gameMode = kGameMode_Practice
//检查游戏中的任何地方
if([MyGame sharedGameObject].gameMode == kGameMode_Practice)
同时在应用终止时保存这些值,并在应用启动时加载相同值.
[[MyGame sharedGameObject] saveData];
根据游戏模式,您可以更改游戏.使用单一通用类进行游戏玩法逻辑并检查游戏模式并进行调整..当你为3个类设计3个单独的类时,将来需要在所有文件中更新一个更好的…所以尽可能多地使用通用代码.
cocos2d-iphone – 用Cocos2d进行UIAutomation测试,可能吗?
具体来说,我想使用zucchini framework来测试我的cocos2d游戏,但这只是使用UIAutomation.
解决方法
''Choose the red bird'' : -> target.tap({x:278,y:36}) ''Press Fire'' : -> target.tap({x:170,y:260})
我们今天的关于iphone – 在iOS中使用Cocoa在后台进行9切缩缩放/拉伸和ios启用缩放的分享就到这里,谢谢您的阅读,如果想了解更多关于cocoa ios iphone xcode 播放GIF动画、cocos2d-iphone – Cocos2d iPhone – Sprite cliping / mask / frame、cocos2d-iphone – 使用cocos2d游戏的状态设计模式、cocos2d-iphone – 用Cocos2d进行UIAutomation测试,可能吗?的相关信息,可以在本站进行搜索。
本文标签: