本文整理汇总了C#中cocos2d.CCSprite.runAction方法的典型用法代码示例。如果您正苦于以下问题:C# CCSprite.runAction方法的具体用法?C# CCSprite.runAction怎么用?C# CCSprite.runAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocos2d.CCSprite
的用法示例。
在下文中一共展示了CCSprite.runAction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: performanceActions
private void performanceActions(CCSprite pSprite)
{
Random random = new Random();
CCSize size = CCDirector.sharedDirector().getWinSize();
pSprite.position = new CCPoint((random.Next() % (int)size.width), (random.Next() % (int)size.height));
float period = 0.5f + (random.Next() % 1000) / 500.0f;
CCRotateBy rot = CCRotateBy.actionWithDuration(period, 360.0f * random.Next());
CCActionInterval rot_back = null;
CCAction permanentRotation = CCRepeatForever.actionWithAction((CCActionInterval)CCSequence.actions(rot, rot_back));
pSprite.runAction(permanentRotation);
float growDuration = 0.5f + (random.Next() % 1000) / 500.0f;
CCActionInterval grow = CCScaleBy.actionWithDuration(growDuration, 0.5f, 0.5f);
CCAction permanentScaleLoop = CCRepeatForever.actionWithAction((CCActionInterval)CCSequence.actionOneTwo(grow, grow.reverse()));
pSprite.runAction(permanentScaleLoop);
}
示例2: onEnter
public override void onEnter()
{
base.onEnter();
float x, y;
CCSize size = CCDirector.sharedDirector().getWinSize();
x = size.width;
y = size.height;
CCSprite bg = CCSprite.spriteWithFile("Images/background3");
addChild(bg, 0, EffectAdvanceScene.kTagBackground);
bg.position = new CCPoint(x / 2, y / 2);
grossini = CCSprite.spriteWithFile("Images/grossinis_sister2");
bg.addChild(grossini, 1, EffectAdvanceScene.kTagSprite1);
grossini.position = new CCPoint(x / 3.0f, 200);
CCActionInterval sc = CCScaleBy.actionWithDuration(2, 5);
CCFiniteTimeAction sc_back = sc.reverse();
grossini.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc, sc_back))));
tamara = CCSprite.spriteWithFile("Images/grossinis_sister1");
bg.addChild(tamara, 1, EffectAdvanceScene.kTagSprite2);
tamara.position = new CCPoint(2 * x / 3.0f, 200);
CCActionInterval sc2 = CCScaleBy.actionWithDuration(2, 5);
CCFiniteTimeAction sc2_back = sc2.reverse();
tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc2, sc2_back))));
CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 28);
label.position = new CCPoint(x / 2, y - 80);
addChild(label);
label.tag = EffectAdvanceScene.kTagLabel;
string strSubtitle = subtitle();
if (strSubtitle != null)
{
CCLabelTTF l = CCLabelTTF.labelWithString(strSubtitle, "Arial", 16);
addChild(l, 101);
l.position = new CCPoint(size.width / 2, size.height - 80);
}
CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage("Images/b1", "Images/b2", this, backCallback);
CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage("Images/r1", "Images/r2", this, restartCallback);
CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage("Images/f1", "Images/f2", this, nextCallback);
CCMenu menu = CCMenu.menuWithItems(item1, item2, item3);
menu.position = new CCPoint(0, 0);
item1.position = new CCPoint(size.width / 2 - 100, 30);
item2.position = new CCPoint(size.width / 2, 30);
item3.position = new CCPoint(size.width / 2 + 100, 30);
addChild(menu, 1);
}
示例3: TMXOrthoZorder
public TMXOrthoZorder()
{
CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-zorder");
base.addChild(map, 0, kTagTileMap);
CCSize s = map.contentSize;
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
m_tamara = CCSprite.spriteWithFile(TestResource.s_pPathSister1);
map.addChild(m_tamara, map.children.Count);
m_tamara.anchorPoint = new CCPoint(0.5f, 0);
CCActionInterval move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / ccMacros.CC_CONTENT_SCALE_FACTOR()));
CCFiniteTimeAction back = move.reverse();
CCFiniteTimeAction seq = CCSequence.actions(move, back);
m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));
schedule((this.repositionSprite));
}
示例4: TMXOrthoVertexZ
public TMXOrthoVertexZ()
{
CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-vertexz");
addChild(map, 0, TileMapTestScene.kTagTileMap);
CCSize s = map.contentSize;
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
// can use any CCSprite and it will work OK.
CCTMXLayer layer = map.layerNamed("trees");
m_tamara = layer.tileAt(new CCPoint(0, 11));
Debug.WriteLine("{0} vertexZ: {1}", m_tamara, m_tamara.vertexZ);
CCActionInterval move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / CCDirector.sharedDirector().ContentScaleFactor));
CCFiniteTimeAction back = move.reverse();
CCFiniteTimeAction seq = CCSequence.actions(move, back);
m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));
schedule(repositionSprite);
}
示例5: TMXIsoVertexZ
public TMXIsoVertexZ()
{
CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test-vertexz");
addChild(map, 0, 1);
CCSize s = map.contentSize;
map.position = new CCPoint(-s.width / 2, 0);
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
// can use any CCSprite and it will work OK.
CCTMXLayer layer = map.layerNamed("Trees");
m_tamara = layer.tileAt(new CCPoint(29, 29));
CCActionInterval move = CCMoveBy.actionWithDuration(10, new CCPoint(300 * 1 / CCDirector.sharedDirector().ContentScaleFactor, 250 * 1 / CCDirector.sharedDirector().ContentScaleFactor));
CCActionInterval back = (CCActionInterval)move.reverse();
CCFiniteTimeAction seq = CCSequence.actions(move, back);
m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));
schedule(repositionSprite);
}
示例6: MoveLayer
public MoveLayer()
{
base.isTouchEnabled = true;//开启触屏事件
CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.kCCDeviceOrientationPortraitUpsideDown;//设置朝向,竖屏
#region Sprite跑动动画
CCSize s = CCDirector.sharedDirector().getWinSize();
// 创建批处理节点,读取plist文件
CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("plist/images/wolf_move");//批处理节点贴图
addChild(batch, 0, 1);
CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("plist/wolf_move");//读取plsit文件
//起始精灵
sprite1 = CCSprite.spriteWithSpriteFrameName("wolf_move1.png");
sprite1.position = (new CCPoint(s.width / 3, s.height / 2));
batch.addChild(sprite1);
// 创建逐帧数组
List<CCSpriteFrame> animFrames = new List<CCSpriteFrame>();
string str = "";
for (int i = 2; i < 8; i++)
{
string temp = "";
temp = i.ToString();
str = string.Format("wolf_move{0}.png", temp);
CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
animFrames.Add(frame);
}
//动画Animate
CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f);//Animation动画信息
sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));//执行动画
#endregion
//直线匀速
//sprite1.runAction(CCMoveTo.actionWithDuration(5.0f, new CCPoint(0, 0)));//移动到坐标(0,0)位置
#region CCEaseInOut
//CCActionInterval move = CCMoveBy.actionWithDuration(3, new CCPoint(280, 0));//CCMoveBy是相当位移动作
//CCActionInterval move_ease_inout = CCEaseInOut.actionWithAction(move);//ease缓冲
//sprite1.runAction(move_ease_inout);
#endregion
}
示例7: TMXIsoZorder
public TMXIsoZorder()
{
CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test-zorder");
addChild(map, 0, 1);
CCSize s = map.contentSize;
////----UXLOG("ContentSize: %f, %f", s.width,s.height);
map.position = (new CCPoint(-s.width / 2, 0));
m_tamara = CCSprite.spriteWithFile(s_pPathSister1);
map.addChild(m_tamara, map.children.Count);
int mapWidth = (int)(map.MapSize.width * map.TileSize.width);
m_tamara.positionInPixels = new CCPoint(mapWidth / 2, 0);
m_tamara.anchorPoint = new CCPoint(0.5f, 0);
CCActionInterval move = CCMoveBy.actionWithDuration(10, new CCPoint(300 * 1 / CCDirector.sharedDirector().ContentScaleFactor, 250 * 1 / CCDirector.sharedDirector().ContentScaleFactor));
CCActionInterval back = (CCActionInterval)move.reverse();
CCFiniteTimeAction seq = CCSequence.actions(move, back);
m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));
schedule((this.repositionSprite));
}
示例8: AddGround
/// <summary>
/// ��һ����ӵ���
/// �ڶ�������box-2d�������潫������Ϊ��̬������ӵ�����������
/// </summary>
private void AddGround()
{
ground = CCSprite.spriteWithFile("imgs/ground/ground");
ground.position = new CCPoint(ground.contentSize.width / 2, ground.contentSize.height / 2);
b2BodyDef groundBodyDef = new b2BodyDef();
groundBodyDef.position = new b2Vec2(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2);
groundBodyDef.userData = ground;
// ��������Ӱ�죬�����˶�
groundBodyDef.type = b2BodyType.b2_staticBody;
// ����ground���˶���ʹ���ٶ���bird�ķ����ٶ�һ��
var action1 = CCMoveTo.actionWithDuration(ground.contentSize.width / (4 * PTM_RATIO * flySpeed),
new CCPoint(ground.contentSize.width / 4, ground.position.y));
var action2 = CCMoveTo.actionWithDuration(0, new CCPoint(ground.contentSize.width / 2, ground.position.y));
var action = CCSequence.actionOneTwo(action1, action2);
var repeatAction = CCRepeatForever.actionWithAction(action);
repeatAction.tag = 0;
ground.runAction(repeatAction);
b2Body groundBody = world.CreateBody(groundBodyDef);
b2PolygonShape groundBox = new b2PolygonShape();
b2FixtureDef boxShapeDef = new b2FixtureDef();
boxShapeDef.shape = groundBox;
groundBox.SetAsBox(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2);
groundBody.CreateFixture(boxShapeDef);
this.addChild(ground);
}
示例9: ParticleDemo
public ParticleDemo()
{
initWithColor( ccTypes.ccc4(127,127,127,255) );
m_emitter = null;
isTouchEnabled = true;
CCSize s = CCDirector.sharedDirector().getWinSize();
CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 28);
addChild(label, 100, 1000);
label.position = new CCPoint(s.width/2, s.height-50);
CCLabelTTF tapScreen = CCLabelTTF.labelWithString("(Tap the Screen)", "Arial", 20);
tapScreen.position = new CCPoint(s.width/2, s.height-80);
addChild(tapScreen, 100);
CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathB1, TestResource.s_pPathB2, this, new SEL_MenuHandler(backCallback) );
CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathR1, TestResource.s_pPathR2, this, new SEL_MenuHandler(restartCallback) );
CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathF1, TestResource.s_pPathF2, this, new SEL_MenuHandler(nextCallback));
CCMenuItemToggle item4 = CCMenuItemToggle.itemWithTarget( this,
new SEL_MenuHandler(toggleCallback),
CCMenuItemFont.itemFromString( "Free Movement" ),
CCMenuItemFont.itemFromString( "Relative Movement" ),
CCMenuItemFont.itemFromString( "Grouped Movement" ));
CCMenu menu = CCMenu.menuWithItems(item1, item2, item3, item4);
menu.position = new CCPoint(0,0);
item1.position = new CCPoint(s.width/2 - 100,30);
item2.position = new CCPoint(s.width/2, 30);
item3.position = new CCPoint(s.width/2 + 100,30);
item4.position = new CCPoint( 0, 100);
item4.anchorPoint = new CCPoint(0,0);
addChild( menu, 100 );
CCLabelAtlas labelAtlas = CCLabelAtlas.labelWithString("0000", "fonts/fnt/images/fps_images", 16, 24, '.');
addChild(labelAtlas, 100, ParticleTestScene.kTagLabelAtlas);
labelAtlas.position = new CCPoint(s.width-66,50);
// moving background
m_background = CCSprite.spriteWithFile(TestResource.s_back3);
addChild(m_background, 5);
m_background.position = new CCPoint(s.width/2 - 120, s.height - 240);
CCActionInterval move = CCMoveBy.actionWithDuration(4, new CCPoint(300,0) );
CCFiniteTimeAction move_back = move.reverse();
CCFiniteTimeAction seq = CCSequence.actions(move, move_back);
m_background.runAction( CCRepeatForever.actionWithAction((CCActionInterval)seq) );
schedule( new SEL_SCHEDULE(step) );
}
示例10: ccTouchesEnded
public override void ccTouchesEnded(List<CCTouch> touches, CCEvent event_)
{
if (nextProjectile != null)
return;
CCTouch touch = touches.FirstOrDefault();
CCPoint location = touch.locationInView(touch.view());
location = CCDirector.sharedDirector().convertToGL(location);
//set up initial location of projectile
CCSize winSize = CCDirector.sharedDirector().getWinSize();
//CCSprite projectile = CCSprite.spriteWithFile(@"images/Projectile");
nextProjectile = CCSprite.spriteWithFile(@"images/Projectile2");
nextProjectile.position = new CCPoint(20, winSize.height / 2);
//Determine offset of location to projectile
float offX = location.x - nextProjectile.position.x;
float offY = location.y - nextProjectile.position.y;
//Bail out if we are shooting or backwards
if (offX <= 0)
{
return;
}
//Determine where we wish to shoot the projectile to
float realX = winSize.width + nextProjectile.contentSize.width / 2;
float ratio = offY / offX;
float realY = realX * ratio + nextProjectile.position.y;
CCPoint realDest = new CCPoint(realX, realY);
//Determine the length of how far we're shooting
float offRealX = realX - nextProjectile.position.x;
float offRealY = realY - nextProjectile.position.y;
float length = (float)Math.Sqrt(offRealX * offRealX + offRealY * offRealY);
float velocity = 480 / 1;//480pixls/lsec
float realMoveDuration = length / velocity;
//Determine angle to face
float angleRadians = (float)Math.Atan(offRealY / offRealX);
float angleDegrees = MathHelper.ToDegrees(angleRadians);
float cocosAngle = -1 * angleDegrees;
float rotateSpeed = (float)(0.5 / Math.PI);//Would take 0.5 seconds to rotate 0.5 radians ,or half a circle
float rotateDuration = Math.Abs(angleRadians * rotateSpeed);
player.runAction(CCSequence.actions(CCRotateTo.actionWithDuration(rotateDuration, cocosAngle), CCCallFunc.actionWithTarget(this, finishShoot)));
//Move projectile to actual endpoint
nextProjectile.runAction(CCSequence.actions(CCMoveTo.actionWithDuration(realMoveDuration, realDest),
CCCallFuncN.actionWithTarget(this, spriteMoveFinished)));
nextProjectile.tag = 2;
}
示例11: addTarget
/// <summary>
/// ���ɵ���
/// </summary>
private void addTarget()
{
Random random = new Random();
var screenWidth = CCDirector.sharedDirector().getWinSize().width;
var screenHeight = CCDirector.sharedDirector().getWinSize().height;
//string number = random.Next(1, 15).ToString("00");
//if (int.Parse(number) / 2 == Convert.ToDouble(number) / 2)
//{
// target = CCSprite.spriteWithFile(@"cars/sonice_cars_" + number);
//}
//else
//{
// target = CCSprite.spriteWithFile(@"cars/lights_" + number);
//}
Monster target = null;
//if (random.Next() % 2 == 0)
//{
// target = WeakAndFastMonster.monster();
//}
//else
//{
// target = StrongAndSlowMonster.monster();
//}
target = level.GetMonster();
var minY = target.contentSize.height / 2;
var maxY = screenHeight - target.contentSize.height / 2;
float rangeY = maxY - minY;
float actualY = (random.Next() % rangeY) + minY;
//create the target slightly off-screen along the right edge;
//and along a random position along the Y axis as calculated above
target.position = new CCPoint(screenWidth + screenWidth / 2, actualY);
//
target.tag = 1;
_targets.Add(target);
this.addChild(target);
//Determine speed of the target
//float minDuration = 4.0f;
//float maxDuration = 7.0f;
float minDuration = target.minMoveDuration;
float maxDuration = target.maxMoveDuration;
float rangeDuration = maxDuration - minDuration;
float actualDuration = random.Next() % rangeDuration + minDuration;
//Create the actions
var actionMove = CCMoveTo.actionWithDuration(actualDuration, new CCPoint(-target.contentSize.width / 2, actualY));
var actionMoveDone = CCCallFuncN.actionWithTarget(this, spriteMoveFinished);
target.runAction(CCSequence.actions(actionMove, actionMoveDone));
}
示例12: AnimationCache
public AnimationCache()
{
CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini");
CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_gray");
CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_blue");
//
// create animation "dance"
//
List<CCSpriteFrame> animFrames = new List<CCSpriteFrame>(15);
string str = "";
for (int i = 1; i < 15; i++)
{
string temp = "";
if (i<10)
{
temp = "0" + i;
}
else
{
temp = i.ToString();
}
str = string.Format("grossini_dance_{0}.png", temp);
CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
animFrames.Add(frame);
}
CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f);
// Add an animation to the Cache
CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance");
//
// create animation "dance gray"
//
animFrames.Clear();
for (int i = 1; i < 15; i++)
{
string temp = "";
if (i < 10)
{
temp = "0" + i;
}
else
{
temp = i.ToString();
}
str = String.Format("grossini_dance_gray_{0}.png", temp);
CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
animFrames.Add(frame);
}
animation = CCAnimation.animationWithFrames(animFrames, 0.2f);
// Add an animation to the Cache
CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_gray");
//
// create animation "dance blue"
//
animFrames.Clear();
for (int i = 1; i < 4; i++)
{
str = String.Format("grossini_blue_0{0}.png", i);
CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str);
animFrames.Add(frame);
}
animation = CCAnimation.animationWithFrames(animFrames, 0.2f);
// Add an animation to the Cache
CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_blue");
CCAnimationCache animCache = CCAnimationCache.sharedAnimationCache();
CCAnimation normal = animCache.animationByName("dance");
CCAnimation dance_grey = animCache.animationByName("dance_gray");
CCAnimation dance_blue = animCache.animationByName("dance_blue");
CCAnimate animN = CCAnimate.actionWithAnimation(normal);
CCAnimate animG = CCAnimate.actionWithAnimation(dance_grey);
CCAnimate animB = CCAnimate.actionWithAnimation(dance_blue);
CCFiniteTimeAction seq = CCSequence.actions(animN, animG, animB);
// create an sprite without texture
CCSprite grossini = new CCSprite();
grossini.init();
CCSize winSize = CCDirector.sharedDirector().getWinSize();
grossini.position = (new CCPoint(winSize.width / 2, winSize.height / 2));
addChild(grossini);
// run the animation
grossini.runAction(seq);
}