本文整理汇总了C#中Cocos2D.CCSpriteFrame类的典型用法代码示例。如果您正苦于以下问题:C# CCSpriteFrame类的具体用法?C# CCSpriteFrame怎么用?C# CCSpriteFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCSpriteFrame类属于Cocos2D命名空间,在下文中一共展示了CCSpriteFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnHandlePropTypeSpriteFrame
protected override void OnHandlePropTypeSpriteFrame(CCNode node, CCNode parent, string propertyName, CCSpriteFrame spriteFrame,
CCBReader reader)
{
if (propertyName == PROPERTY_NORMALDISPLAYFRAME)
{
if (spriteFrame != null)
{
((CCMenuItemImage) node).SetNormalSpriteFrame(spriteFrame);
}
}
else if (propertyName == PROPERTY_SELECTEDDISPLAYFRAME)
{
if (spriteFrame != null)
{
((CCMenuItemImage) node).SetSelectedSpriteFrame(spriteFrame);
}
}
else if (propertyName == PROPERTY_DISABLEDDISPLAYFRAME)
{
if (spriteFrame != null)
{
((CCMenuItemImage) node).SetDisabledSpriteFrame(spriteFrame);
}
}
else
{
base.OnHandlePropTypeSpriteFrame(node, parent, propertyName, spriteFrame, reader);
}
}
示例2: SpriteAnimationSplit
public SpriteAnimationSplit()
{
CCSize s = CCDirector.SharedDirector.WinSize;
CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation");
// manually add frames to the frame cache
CCSpriteFrame frame0 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 0, 132, 132));
CCSpriteFrame frame1 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 0, 132, 132));
CCSpriteFrame frame2 = new CCSpriteFrame(texture, new CCRect(132 * 2, 132 * 0, 132, 132));
CCSpriteFrame frame3 = new CCSpriteFrame(texture, new CCRect(132 * 3, 132 * 0, 132, 132));
CCSpriteFrame frame4 = new CCSpriteFrame(texture, new CCRect(132 * 0, 132 * 1, 132, 132));
CCSpriteFrame frame5 = new CCSpriteFrame(texture, new CCRect(132 * 1, 132 * 1, 132, 132));
//
// Animation using Sprite BatchNode
//
CCSprite sprite = new CCSprite(frame0);
sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));
AddChild(sprite);
var animFrames = new List<CCSpriteFrame>(6);
animFrames.Add(frame0);
animFrames.Add(frame1);
animFrames.Add(frame2);
animFrames.Add(frame3);
animFrames.Add(frame4);
animFrames.Add(frame5);
CCAnimation animation = new CCAnimation(animFrames, 0.2f);
CCAnimate animate = new CCAnimate (animation);
CCActionInterval seq = (CCActionInterval)(new CCSequence(animate,
new CCFlipX(true),
(CCFiniteTimeAction)animate.Copy(),
new CCFlipX(false)
));
sprite.RunAction(new CCRepeatForever (seq));
//animFrames->release(); // win32 : memory leak 2010-0415
}
示例3: LoadCocos2DDictionary
private void LoadCocos2DDictionary(PlistDictionary dict, CCTexture2D texture)
{
PlistDictionary metadataDict = null;
if (dict.ContainsKey("metadata"))
{
metadataDict = dict["metadata"].AsDictionary;
}
PlistDictionary framesDict = null;
if (dict.ContainsKey("frames"))
{
framesDict = dict["frames"].AsDictionary;
}
// get the format
int format = 0;
if (metadataDict != null)
{
format = metadataDict["format"].AsInt;
}
// check the format
if (format < 0 || format > 3)
{
throw (new NotSupportedException("PList format " + format + " is not supported."));
}
foreach (var pair in framesDict)
{
PlistDictionary frameDict = pair.Value.AsDictionary;
CCSpriteFrame spriteFrame = null;
if (format == 0)
{
float x = 0f, y = 0f, w = 0f, h = 0f;
x = frameDict["x"].AsFloat;
y = frameDict["y"].AsFloat;
w = frameDict["width"].AsFloat;
h = frameDict["height"].AsFloat;
float ox = 0f, oy = 0f;
ox = frameDict["offsetX"].AsFloat;
oy = frameDict["offsetY"].AsFloat;
int ow = 0, oh = 0;
ow = frameDict["originalWidth"].AsInt;
oh = frameDict["originalHeight"].AsInt;
// check ow/oh
if (ow == 0 || oh == 0)
{
CCLog.Log(
"cocos2d: WARNING: originalWidth/Height not found on the CCSpriteFrame. AnchorPoint won't work as expected. Regenerate the .plist or check the 'format' metatag");
}
// abs ow/oh
ow = Math.Abs(ow);
oh = Math.Abs(oh);
// create frame
spriteFrame = new CCSpriteFrame(
texture,
new CCRect(x, y, w, h),
false,
new CCPoint(ox, oy),
new CCSize(ow, oh)
);
}
else if (format == 1 || format == 2)
{
var frame = CCRect.Parse(frameDict["frame"].AsString);
bool rotated = false;
// rotation
if (format == 2)
{
if (frameDict.ContainsKey("rotated"))
{
rotated = frameDict["rotated"].AsBool;
}
}
var offset = CCPoint.Parse(frameDict["offset"].AsString);
var sourceSize = CCSize.Parse(frameDict["sourceSize"].AsString);
// create frame
spriteFrame = new CCSpriteFrame(texture, frame, rotated, offset, sourceSize);
}
else if (format == 3)
{
var spriteSize = CCSize.Parse(frameDict["spriteSize"].AsString);
var spriteOffset = CCPoint.Parse(frameDict["spriteOffset"].AsString);
var spriteSourceSize = CCSize.Parse(frameDict["spriteSourceSize"].AsString);
var textureRect = CCRect.Parse(frameDict["textureRect"].AsString);
bool textureRotated = false;
if (frameDict.ContainsKey("textureRotated"))
{
textureRotated = frameDict["textureRotated"].AsBool;
}
//.........这里部分代码省略.........
示例4: CCMaskedSprite
public CCMaskedSprite(CCSpriteFrame pSpriteFrame, byte[] mask)
: base(pSpriteFrame)
{
_MyMask = mask;
}
示例5: InitWithSpriteFrame
public virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
{
Debug.Assert(spriteFrame != null, "Sprite frame must be not nil");
CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
bool pReturn = InitWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, capInsets);
return pReturn;
}
示例6: AddSpriteFrame
public void AddSpriteFrame(CCSpriteFrame pobFrame, string pszFrameName)
{
if (!_AllowFrameOverwrite && m_pSpriteFrames.ContainsKey(pszFrameName))
{
throw (new ArgumentException("The frame named " + pszFrameName + " already exists."));
}
m_pSpriteFrames[pszFrameName] = pobFrame;
}
示例7: AddSpriteFrameWithTexture
public void AddSpriteFrameWithTexture(CCTexture2D pobTexture, CCRect rect)
{
CCSpriteFrame pFrame = new CCSpriteFrame(pobTexture, rect);
AddSpriteFrame(pFrame);
}
示例8: AddSpriteFrame
public void AddSpriteFrame(CCSpriteFrame pFrame)
{
var animFrame = new CCAnimationFrame();
animFrame.InitWithSpriteFrame(pFrame, 1.0f, null);
m_pFrames.Add(animFrame);
// update duration
m_fTotalDelayUnits++;
}
示例9: SetBackgroundSpriteFrameForState
/**
* Sets the background spriteFrame to use for the specified button state.
*
* @param spriteFrame The background spriteFrame to use for the specified state.
* @param state The state that uses the specified image. The values are described
* in "CCControlState".
*/
public virtual void SetBackgroundSpriteFrameForState(CCSpriteFrame spriteFrame, CCControlState state)
{
CCScale9Sprite sprite = new CCScale9SpriteFrame(spriteFrame);
SetBackgroundSpriteForState(sprite, state);
}
示例10: SetSelectedSpriteFrame
public void SetSelectedSpriteFrame(CCSpriteFrame frame)
{
SelectedImage = new CCSprite(frame);
}
示例11: LoadAppleDictionary
private void LoadAppleDictionary(PlistDictionary dict, CCTexture2D texture)
{
var version = dict.ContainsKey ("version") ? dict ["version"].AsInt : 0;
if (version != 1)
throw (new NotSupportedException("Binary PList version " + version + " is not supported."));
var images = dict.ContainsKey ("images") ? dict ["images"].AsArray : null;
foreach (var imageEntry in images)
{
// we only support one image for now
var imageDict = imageEntry.AsDictionary;
var path = imageDict ["path"].AsString;
path = Path.Combine(plistFilePath, CCFileUtils.RemoveExtension(path));
if (!CCTextureCache.SharedTextureCache.Contains (path))
texture = CCTextureCache.SharedTextureCache.AddImage (path);
else
texture = CCTextureCache.SharedTextureCache[path];
// size not used right now
//var size = CCSize.Parse(imageDict ["size"].AsString);
var subImages = imageDict ["subimages"].AsArray;
foreach (var subImage in subImages) {
CCSpriteFrame spriteFrame = null;
var subImageDict = subImage.AsDictionary;
var name = subImageDict ["name"].AsString;
var alias = subImageDict ["alias"].AsString;
var isFullyOpaque = true;
if (subImageDict.ContainsKey ("isFullyOpaque"))
isFullyOpaque = subImageDict ["isFullyOpaque"].AsBool;
var textureRect = CCRect.Parse (subImageDict ["textureRect"].AsString);
var spriteOffset = CCPoint.Parse (subImageDict ["spriteOffset"].AsString);
// We are going to override the sprite offset for now to be 0,0
// It seems the offset is calculated off of the original size but if
// we pass this offset it throws our center position calculations off.
spriteOffset = CCPoint.Zero;
var textureRotated = false;
if (subImageDict.ContainsKey ("textureRotated")) {
textureRotated = subImageDict ["textureRotated"].AsBool;
}
var spriteSourceSize = CCSize.Parse (subImageDict ["spriteSourceSize"].AsString);
var frameRect = textureRect;
if (textureRotated)
frameRect = new CCRect (textureRect.Origin.X, textureRect.Origin.Y, textureRect.Size.Height, textureRect.Size.Width);
#if DEBUG
CCLog.Log ("texture {0} rect {1} rotated {2} offset {3}, sourcesize {4}", name, textureRect, textureRotated, spriteOffset, spriteSourceSize);
#endif
// create frame
spriteFrame = new CCSpriteFrame (
texture,
frameRect,
textureRotated,
spriteOffset,
spriteSourceSize
);
_spriteFrames [name] = spriteFrame;
}
}
}
示例12: InitWithSpriteFrame
protected virtual bool InitWithSpriteFrame(CCSpriteFrame pSpriteFrame)
{
mSpriteFrame = pSpriteFrame;
return true;
}
示例13: CCBSetSpriteFrame
public CCBSetSpriteFrame(CCSpriteFrame pSpriteFrame)
{
InitWithSpriteFrame(pSpriteFrame);
}
示例14: CreateAnimateAction
public CCAnimate CreateAnimateAction()
{
var frameList = new List<CCSpriteFrame>();
for (var i = 0; i < 7; i++)
{
var texture = CreateCharacterTexture();
var sprite = new CCSpriteFrame(texture, new CCRect(0, 0, texture.ContentSize.Width, texture.ContentSize.Height));
frameList.Add(sprite);
}
var animation = new CCAnimation(frameList, 0.1f);
var animate = new CCAnimate (animation);
return animate;
}
示例15: SetSpriteFrame
public void SetSpriteFrame(CCSpriteFrame spriteFrame)
{
CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
UpdateWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, CCRect.Zero);
// Reset insets
_insetLeft = 0;
_insetTop = 0;
_insetRight = 0;
_insetBottom = 0;
}