回答
這解決了它。
回答以下是從我在遊戲開發網站收到回覆複製:https://gamedev.stackexchange.com/questions/38071/how-to-make-a-sprite-using-coregraphics-ios-cocos2d-iphone
我不知道cocos2d的,所以我只能給你約在iOS CoreGraphics中的一些技巧。
首先,簡單的情況下,如果你可以從UIImage或CGImageRef創建精靈。
/* function that draw your shape in a CGContextRef */
void DrawShape(CGContextRef ctx)
{
// draw a simple triangle
CGContextMoveToPoint(ctx, 50, 100);
CGContextAddLineToPoint(ctx, 100, 0);
CGContextAddLineToPoint(ctx, 0, 0);
CGContextClosePath(ctx);
}
void CreateImage(void)
{
UIGraphicsBeginImageContext(CGSizeMake(100, 100));
DrawShape(UIGraphicsGetCurrentContext());
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// now you've got an (autorelease) UIImage, that you can use to
// create your sprite.
// use image.CGImage if you need a CGImageRef
}
如果您需要提供數據的緩衝區,並創建自己的CGContextRef:
CGContextRef CreateBitmapContextWithData(int width, int height, void *buffer)
{
CGContextRef ctx;
CGColorSpaceRef colorspace;
size_t bytesPerRow;
size_t bitsPerComponent;
size_t numberOfComponents;
CGImageAlphaInfo alpha;
bitsPerComponent = 8;
alpha = kCGImageAlphaPremultipliedLast;
numberOfComponents = 1;
colorspace = CGColorSpaceCreateDeviceRGB();
numberOfComponents += CGColorSpaceGetNumberOfComponents(colorspace);
bytesPerRow = (width * numberOfComponents);
ctx = CGBitmapContextCreate(buffer, width, height, bitsPerComponent, bytesPerRow, colorspace, alpha);
CGColorSpaceRelease(colorspace);
return ctx;
}
void CreateImageOrGLTexture(void)
{
// use pow2 width and height to create your own glTexture ...
void *buffer = calloc(1, 128 * 128 * 4);
CGContextRef ctx = CreateBitmapContextWithData(128, 128, buffer);
// draw you shape
DrawShape(ctx);
// you can create a CGImageRef with this context
// CGImageRef image = CGBitmapContextCreateImage(ctx);
// you can create a gl texture with the current buffer
// glBindTexture(...)
// glTexParameteri(...)
// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
CGContextRelease(ctx);
free(buffer);
}
所有CGContext上功能看到蘋果文檔:https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html
希望這有助於。
最終用戶回答。
做所有的核心圖形工作,然後你將有一個CGImageRef。使用該參考,您可以使用
+ (id)spriteWithCGImage:(CGImageRef)image key:(NSString *)key
on CCSprite。
在這裏得到了我的答案。 http://gamedev.stackexchange.com/questions/38071/how-to-make-a-sprite-using-coregraphics-ios-cocos2d-iphone/38111#38111 感謝您的幫助! – PeteBob
- 1. cocos2d:交換雪碧
- 2. Cocos2d雪碧鏈接
- 3. Cocos2d雪碧移動速度
- 4. Cocos2d。雪碧要消失
- 5. Cocos2d - 雪碧沒有動畫
- 6. 曲線雪碧運動COCOS2D
- 7. Cocos2D拖放雪碧問題
- 8. Cocos2D雪碧相對運動
- 9. cocos2d雪碧彈跳效果
- 10. 雪碧速度Cocos2d 3.0
- 11. 如何使雪碧
- 12. 使用Monogame繪製雪碧
- 13. (Cocos2D)雪碧不是完全坐在其他雪碧的頂部?
- 14. 在Cocos2D和Spritebuilder中爲動畫製作雪碧
- 15. 用觸摸旋轉雪碧 - Cocos2d
- 16. 製作雪碧不可移動... [花栗鼠與Cocos2D中]
- 17. 如何檢索操作從雪碧在cocos2d
- 18. cocos2d着色雪碧白與不透明
- 19. 雪碧突然消失了cocos2d
- 20. 在Cocos2d中動畫雪碧圖片
- 21. 在cocos2d中停止雪碧動畫
- 22. 雪碧框架動畫Cocos2d 3.0
- 23. UIGestureRecognizer不會旋轉雪碧 - Cocos2d
- 24. iOS Dev:使用OpenGL ES繪製圖像/雪碧
- 25. 雪碧
- 26. 隨機雪碧與雪碧池
- 27. Python - 雪碧追逐另一個雪碧
- 28. PHP動態雪碧創作
- 29. cocos2d setOpacity在CCRenderTexture上使用雪碧時爲白色
- 30. 在Cocos2D中使用CDAudioManager動畫卡通雪碧
不是什麼卑鄙的東西,但我認爲解決方案已經在那裏,可以谷歌:http://www.cocos2d-iphone.org/forum/topic/2681 ...但是,這是非常慢。 – Mazyod
我很欣賞這個鏈接,但它不完全相關,並且超過2年。我一直在盡我的努力尋找答案,但我似乎無法找到任何解釋如何使用核心圖形來創建一個在cocos2d中使用的精靈的形狀。 – PeteBob