ccsprite

How to swap the sprite in the CCSprite object in Cocos2d-X

自闭症网瘾萝莉.ら 提交于 2019-12-09 09:14:07
问题 I have an object that inherited from CCSprite. I want from inside this object to change the image. How do I change the image (sprite) without creating a new CCSprite object in Cocos2d-X? Thanks, Adrian. 回答1: mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png")); No need to alter your custom class.. Hope this helps.. :) 回答2: Works for me: mySprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("frame_name")); Before you need to

Accessing Objects in other Layers (cocos2d)

被刻印的时光 ゝ 提交于 2019-12-09 06:27:30
问题 I was playing around with a Joystick moving a Sprite around in one layer. Now, according to best practice, the Joystick and the Sprite have to be in different Layers of the same scene. I have managed to separate these, yet I am now completely stuck having absolutely no clue whatsoever how to pass joystick commands from one layer to another? What is the recommended way to do this? Scene Game Play Layer Sprite Game Control Layer Joystick When the joystick is manipulated I need to pass this info

Cocos2d: CCSprite initWithFile in CCSprite subclass crashes

喜你入骨 提交于 2019-12-08 08:36:49
问题 I have cocos2d project with custom CCSprite subclass: MyCustomSprite.h: #import "cocos2d.h" @interface MyCustomSprite : CCSprite @end MyCustomSprite.m: #import "MyCustomSprite.h" @implementation MyCustomSprite - (id)init { self = [super initWithFile:@"index.png"]; return self; } @end For some strange reason, this code will crash with "EXC_BAD_ACCESS". But in spite of this, if i init super as ususal and then write code from CCSprite's initWithFile and initWithTexture, it will work fine: self =

CCSprite: Batched sprites should use the same texture as the batchnode?

落爺英雄遲暮 提交于 2019-12-06 10:11:36
I keep getting a crash that says: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode' I am not quite sure what this means. I googled the crash but got no results. Also this only happens when I go back to my first scene after coming back from the second scene in my game. I double checked my code and I make sure all the images in my sprite sheets are added as children to the batch node. I also make sure the images in my app that aren't in my sprite sheet are added as a child to my layer

Cocos2d - move a sprite from point A to point B in a sine wave motion

*爱你&永不变心* 提交于 2019-12-05 17:32:24
What would be the best way to do this? I see the CCEaseSineInOut action but it doesn't look like that could be used to do this. I need to move from one side of the screen to the other. The sprite should move in a sine-wave pattern across the screen. I always like to have complete control over CCNode motion. I only use CCAction s to do very basic things. While your case sounds simple enough to possibly do with CCAction s, I will show you how to move a CCNode according to any function over time. You can also change scale, color, opacity, rotation, and even anchor point with the same technique.

Cocos2d: 6 doubts on usage of CCSpriteBatchNode

倖福魔咒の 提交于 2019-12-05 06:12:47
问题 I am wondering how to optimize the usage of CCSpriteBatchNode. In other words I understand that: 1) Each CCSpriteBatchNode instance performs one call to the draw method, resulting in a reduction of OpenGL calls and hence significant performance improvement 2) Each CCSpriteBatchNode can refer to one and only texture atlas What I am not 100% sure and I would like your answer is: 3) If I have one texture atlas, e.g. game-art-hd.png, and create several CCSpriteBatchNode in various classes will I

[cocos2dx android]Rendering CCSprite using raw data from Bitmap

自古美人都是妖i 提交于 2019-12-04 17:46:00
I am trying to fetch an image from a URL into a Bitmap and then using the raw data from the Bitmap am trying to create a CCSprite. The issue here is that the image is corrupted when I display the sprite. I created a standalone android only application(no cocos2dx) and used the same code to fetch and display the Bitmap and its displayed correctly. Any reason why the image is not being properly rendered in cocos2dx? My code to fetch the image from the URL is: String urlString = "http://www.mathewingram.com/work/wp-content/themes/thesis/rotator/335f69c5de_small.jpg";//http://graph.facebook.com/"

How to switch the image of a CCSprite

佐手、 提交于 2019-12-03 14:46:41
I have a CCSprite that is initialized using [CCSprite spriteWithSpriteFrameName:@"plist_file_key_here.png"] . I have already added all the sprites from my plist file to CCSpriteFrameCache. I have tried setting the texture like this: CCSpriteFrame * frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:name]; NSAssert(frame.texture!=nil, @"frame.texture can't equal nil"); //this works fine [sprite setTexture:frame.texture]; //doesn't cause a white square to appear, just doesn't switch the image. As I said in my comments, this doesn't work. I think it has something to do with

How to swap the sprite in the CCSprite object in Cocos2d-X

早过忘川 提交于 2019-12-03 12:16:35
I have an object that inherited from CCSprite. I want from inside this object to change the image. How do I change the image (sprite) without creating a new CCSprite object in Cocos2d-X? Thanks, Adrian. mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png")); No need to alter your custom class.. Hope this helps.. :) Works for me: mySprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("frame_name")); Before you need to load you sprites in cache: CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprite_atlas

how to obtain a CCSprite's width and height in cocos2d for iphone

三世轮回 提交于 2019-12-03 06:38:21
问题 That's the question xD Given an instance of a CCSprite in cocos2d in iphone, what method can I use to obtain the image width and height? 回答1: The CCSprite class has a bounding box property that's a CGRect: CCSprite *sprite = [CCSprite spriteWithFile: @"file.png"]; int width = [sprite boundingBox].size.width; I added a width and height methods to my CCSprite subclass. -(CGFloat) width { return [self boundingBox].size.width; } -(CGFloat) height { return [self boundingBox].size.height; } 回答2: