ccsprite

How to resize the the animating sprite in cocos2d-x

久未见 提交于 2019-12-13 05:04:06
问题 I want to change the size of a Sprite which is animating. How can I do this ? I tried to change its size by using setScale property but it is not working here. where I am doing wrong ? CCArray* frames = CCArray::createWithCapacity(3); CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); char file[100] = {0}; for (int i = 0; i < 3; i++) { sprintf(file, "bird%d.png", i); CCSpriteFrame* frame = frameCache->spriteFrameByName(file); frames->addObject(frame); } CCAnimation

CCSprite is moved when using CCScaleTo or CCScaleBy

て烟熏妆下的殇ゞ 提交于 2019-12-13 04:26:38
问题 I almost have read everything about Anchor Point and scaling. I still have no idea what is going on with a sprites position when i scale it. The scenario is this: When i tap on screen, sprite's width will decrease about %50 and height will increase about same scale. Then it will get back to its normal scale. id scaleUpAction = [CCEaseInOut actionWithAction:[CCScaleTo actionWithDuration:.35 scaleX:0.5 scaleY:1.5] rate:1.0]; id scaleDownAction = [CCEaseInOut actionWithAction:[CCScaleTo

Cocos2d: Is it ok to have a pointer to a parent's class pointer?

Deadly 提交于 2019-12-13 03:52:16
问题 Silly question. Cocos2d is build around the parent-child hierarchy. I was wondering if it is ok to have a parent class (e.g. GameScene) and initialize a child class (e.g. SpriteHandler) with a pointer to a member of the parent class (e.g. CCSpriteBatchNode*). I am trying to do this to optimize the number of CCSpriteBatchNodes. Here is a code snippet of my main class (GameScene style). #import <Foundation/Foundation.h> #import "cocos2d.h" enum ShooterSceneLayerTags { HudLayerTag = 0, };

cocos2d-x convert UIImage to CCSprite

女生的网名这么多〃 提交于 2019-12-13 00:41:44
问题 has anyone an idea how to convert a UIImage to cocos2d-x CCSprite. My latest attempt was was: 1. Store the UIImage as png on the phone 2. Load the png as a CCSprite [UIImagePNGRepresentation(photo) writeToFile:imagePath atomically:true]; CCSprite *sprite = CCSprite::spriteWithFile(imagePath); But this crashed in CCObject retain function void CCObject::retain(void) { CCAssert(m_uReference > 0, "reference count should greater than 0"); ++m_uReference; } And I do not understand how Walzer Wangs

How to transfer a CCSprite from one parent to another?

社会主义新天地 提交于 2019-12-12 11:18:27
问题 I have a CCSprite called sprite that is a child of a CCLayer called movingLayer that is itself a child of the current CCLayer running my game logic, so it is self in this case. movingLayer is moving back and forth across the screen in a repeat forever action and sprite is riding along on it. I want to get sprite to "get off" of movingLayer and "get on" to self where it can do some actions of its own. When I try to do this, I need to tell movingLayer to remove sprite and self to add sprite.

Cocos2D Sprite Relative Movement

夙愿已清 提交于 2019-12-11 15:24:22
问题 I have a problem that I can't seem to solve. I would like to move a sprite on the screen based on finger movements, but instead of making the sprite move towards the touch position I would like the sprite to move in the same way the finger moves on the screen. Example: User puts his/her finger on the screen (any position) and then drags the finger on the screen by 200 pixel to the left, the sprite should also move of 200 pixels to the left. My approach was to store the position of the player

Spritesheet with Cocos2d not displaying anything

社会主义新天地 提交于 2019-12-11 10:27:53
问题 I'm trying to write a demo application to learn how to better use sprite sheets in Cocos2d. So far, I've gotten sprites all ready to go, the sheet looks great, the code looks good... but the sprites aren't showing up! I have Dice objects that contain the sprite, and some functions to select a random face before animating the die onto the screen. It's supposed to be like you're rolling them. The order of operation that I've used is: Add the plist of sprite data to the frame cache Create the

How to Convert a CCSprite image to UIImage?

半腔热情 提交于 2019-12-11 01:37:03
问题 As the title, I have mentioned the code below CCSprite *sprite = (CCSprite *)node; CCTexture2D *texture2d = [sprite texture]; How can I get a UIImage *p from sprite? 回答1: In your case just add next methood into your class: - (UIImage *) imageFromSprite :(CCSprite *)sprite { int tx = sprite.contentSize.width; int ty = sprite.contentSize.height; CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:tx height:ty]; sprite.anchorPoint = CGPointZero; [renderer begin]; [sprite visit];

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

若如初见. 提交于 2019-12-10 09:27:09
问题 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. 回答1: 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

Moving Box2d Bodies Like CCSprite Objects

被刻印的时光 ゝ 提交于 2019-12-09 13:00:06
问题 In cocos2d, you can ease in CCSprites and move them around in all kinds of ways. Most importantly - they can have easing in/out. For most games this is desirable for smooth movement etc. id action = [CCMoveTo actionWithDuration:dur position:pos]; move = [CCEaseInOut actionWithAction:action rate:2]; [self runAction: move]; When moving a box2d body, the sprite attached to it is updated after the box2d step(). Moving the sprite and then updating the body is not an option here, as it entirely