当前位置: 首页>>代码示例>>C++>>正文


C++ CCSpriteFrame::getOffsetInPixels方法代码示例

本文整理汇总了C++中CCSpriteFrame::getOffsetInPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ CCSpriteFrame::getOffsetInPixels方法的具体用法?C++ CCSpriteFrame::getOffsetInPixels怎么用?C++ CCSpriteFrame::getOffsetInPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCSpriteFrame的用法示例。


在下文中一共展示了CCSpriteFrame::getOffsetInPixels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: playAnimation

 // Starts playing a given animation (or nothing if this animation is already playing)
 void CocosSpriteActorView::playAnimation(const std::string &name)
 {        
     if (name != _currentAnimation)
     {
         SpriteActorView::playAnimation(name);
     
         if (_currentAnimation != "")
         {
             // Sprite wasn't created yet. Create and set parameters
             if (!_ccSprite)
             {
                 _ccSprite = CCSprite::spriteWithSpriteFrame(((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame());    
                 if (_ccSprite)
                 {
                     setPosition(getPosition());
                     setAngle(getAngle());
                     setScale(getScale());
                     setZOrder(getZOrder());
                     setVisible(isVisible());
                     setAlpha(getAlpha());
                 }
             }
             
             // The sprite was created, change texture
             if (_ccSprite)
             {
                 bool isAnimation = _animations[_currentAnimation]->getFrameCount() > 1;
                 
                 CCSpriteFrame *frame = ((CocosAnimation *)_animations[_currentAnimation].get())->getFirstFrame();
                 _ccSprite->setTexture(frame->getTexture());
                 CCRect frameRect = frame->getRectInPixels();
                 if (isAnimation)
                 {
                     frameRect.origin = frame->getOffsetInPixels();
                 }
                 _ccSprite->setTextureRect(frameRect);
                 _ccSprite->setDisplayFrame(frame);
                 
                 // If this animation contains more than one frame, play the animation
                 if (isAnimation)
                 {
                     _ccSprite->runAction(((CocosAnimation *)_animations[_currentAnimation].get())->getAnimationAction());
                 }
             }
             
         }
     }
 }
开发者ID:Avnerus,项目名称:ichigo,代码行数:49,代码来源:CocosSpriteActorView.cpp

示例2: CCImage

JNIEXPORT void JNICALL Java_org_cocos2dx_lib_CCImage_1richlabel_nativeGetSpriteFrameInfo
  (JNIEnv * env, jclass clazz, jstring jPlist, jstring jAtlas, jstring jImageName, jobject jFrame) {
	// get c string
	const char* plist = (const char*)env->GetStringUTFChars(jPlist, NULL);
	const char* atlas = (const char*)env->GetStringUTFChars(jAtlas, NULL);
	const char* imageName = (const char*)env->GetStringUTFChars(jImageName, NULL);

	// get sprite frame
	CLBitmapDC& bitmapDC = CLBitmapDC::sharedCLBitmapDC();
	CCSpriteFrameCache* fc = CCSpriteFrameCache::sharedSpriteFrameCache();
	if(!fc->spriteFrameByName(imageName)) {
		if(bitmapDC.m_decryptFunc) {
			// load encryptd data
			unsigned long len;
			char* data = (char*)CCFileUtils::sharedFileUtils()->getFileData(atlas, "rb", &len);

			// create texture
			int decLen;
			const char* dec = (*bitmapDC.m_decryptFunc)(data, (int)len, &decLen);
			CCImage* image = new CCImage();
			image->initWithImageData((void*)dec, decLen);
			image->autorelease();
			CCTexture2D* tex = CCTextureCache::sharedTextureCache()->addUIImage(image, atlas);

			// add
			fc->addSpriteFramesWithFile(plist, tex);

			// free
			if(data != dec)
				free((void*)dec);
			free(data);
		} else {
			fc->addSpriteFramesWithFile(plist, atlas);
		}
	}
	CCSpriteFrame* frame = fc->spriteFrameByName(imageName);

	// get java frame info
	jclass frameClass = env->FindClass("org/cocos2dx/lib/CCImage_richlabel$AtlasFrame");
	jfieldID fid_x = env->GetFieldID(frameClass, "x", "I");
	jfieldID fid_y = env->GetFieldID(frameClass, "y", "I");
	jfieldID fid_w = env->GetFieldID(frameClass, "w", "I");
	jfieldID fid_h = env->GetFieldID(frameClass, "h", "I");
	jfieldID fid_offsetX = env->GetFieldID(frameClass, "offsetX", "I");
	jfieldID fid_offsetY = env->GetFieldID(frameClass, "offsetY", "I");
	jfieldID fid_sourceWidth = env->GetFieldID(frameClass, "sourceWidth", "I");
	jfieldID fid_sourceHeight = env->GetFieldID(frameClass, "sourceHeight", "I");
	jfieldID fid_rotated = env->GetFieldID(frameClass, "rotated", "Z");

	// copy frame info to java object
	const CCSize& sourceSize = frame->getOriginalSizeInPixels();
	bool rotated = frame->isRotated();
	const CCRect& frameRect = frame->getRectInPixels();
	const CCPoint& offset = frame->getOffsetInPixels();
	env->SetIntField(jFrame, fid_x, (int)frameRect.origin.x);
	env->SetIntField(jFrame, fid_y, (int)frameRect.origin.y);
	env->SetIntField(jFrame, fid_w, (int)frameRect.size.width);
	env->SetIntField(jFrame, fid_h, (int)frameRect.size.height);
	env->SetIntField(jFrame, fid_offsetX, (int)offset.x);
	env->SetIntField(jFrame, fid_offsetY, (int)offset.y);
	env->SetIntField(jFrame, fid_sourceWidth, (int)sourceSize.width);
	env->SetIntField(jFrame, fid_sourceHeight, (int)sourceSize.height);
	env->SetBooleanField(jFrame, fid_rotated, rotated);

	// release
	env->DeleteLocalRef(frameClass);
	env->ReleaseStringUTFChars(jPlist, plist);
	env->ReleaseStringUTFChars(jAtlas, atlas);
	env->ReleaseStringUTFChars(jImageName, imageName);
}
开发者ID:NewtrendDesign,项目名称:cocos2dx-better,代码行数:70,代码来源:org_cocos2dx_lib_CCImage_richlabel.cpp


注:本文中的CCSpriteFrame::getOffsetInPixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。