2

Cocos2d-android - I have an animation which has 5 Frames. which will rolling in position. how to make the button rolling like a globe.

Bebin T.N
  • 2,539
  • 1
  • 24
  • 28

2 Answers2

1

I don't know if it can be done like menuitem, but you can make a sprite with forever action(animation of yours 5 frames)and in ccTouchesBegan/ccTouchesEnded you add code to go to another scene or for do an another function after touching on your sprite.

`private CCSprite animatedButton; // Make your sprite visible at begin of your class/layer.`


`animatedButton = CCSprite.sprite("yourImage.png");
 CCAnimation buttonAnimation = CCAnimation.animation("", 1f);
 buttonAnimation.addFrame("1.png");     
 buttonAnimation.addFrame("2.png"); 
 addChild(animatedButton, 1);
 CCIntervalAction buttonAction = CCAnimate.action(duration, buttonAnimation, false);
 animatedButton.runAction(CCRepeatForever.action(buttonAction));
 `

Now should be your button(CCSprite) animating. I didnt tried code. And now you just find out in ccTouchesBegan or ccTouchesEnded if your button was touched. If yes, you could do what you want. :)

`if(animatedButton.getBoundingBox.contains(x,y)){
   CCScene scene = GameLayer.scene();       
   CCDirector.sharedDirector().replaceScene(scene);
 }`

X and y are coordinates of touch;

StevoF
  • 477
  • 5
  • 17
  • Sorry Steve your code is useful for replace a sceen. I asked about button animation. – Bebin T.N Jul 29 '13 at 14:38
  • 1
    I need how to Animate a menuitem. – Bebin T.N Jul 30 '13 at 09:47
  • I have seen that menuitem has runAction function, so try to run CCRepeatAction on it like in code above on animatedButton, but I am not sure it will be work. I try it maybe layter when I will be on computer. But with ccTouchesBegan, ccTouchesMoved and ccTouchesEnded together you can get same effect like for menuitems (more sprites). Or is there something more/specific which I can help you with? – StevoF Jul 30 '13 at 10:52
0

You can add animations to menuitem. Like this

CCMenuItem button=CCMenuItemImage.item(image, image, this, "label");
    button.setScaleX((winSize.width/8.0f)/image.getTexture().getWidth());
    button.setScaleY((winSize.height/8.0f)/image.getTexture().getHeight());
    button.setPosition(winSize.width/2,winSize.height+50);

    CCAction actionMove42=CCSequence.actions(CCDelayTime.action(0.3f), CCEaseBackOut.action(CCMoveTo.action(1.0f, CGPoint.ccp(0,0))));
    button.runAction(actionMove42);
Sandeep R
  • 2,284
  • 3
  • 25
  • 51