-1
-(void) redafter1
{

red = [CCMenuItemImage
       itemFromNormalImage:@"red.png" selectedImage:@"redclick.png"];
red.position = ccp(175, 725);
redMenu = [CCMenu menuWithItems:red, nil];
redMenu.position = CGPointZero;
redMenu.scale = .75;
[self addChild:redMenu z:10];
}

How would I go about animating this object to move to another location on the screen? I am very new to this, please be basic in your explanation.

Jon Shier
  • 12,200
  • 3
  • 35
  • 37

2 Answers2

0

If you want to animate CCNode (this is base class of all cocos2d objects such as layers, sprites, labels, menuitems, etc.), you have to use actions mechanism. To move object, use CCMoveTo, CCMoveBy actions with runAction: method.

id moveAction = [CCMoveTo actionWithDuration: animationDuration position: targetPosition];
[nodeToAnimate runAction: moveAction];

In your case if you will run action on the object right after adding it to the some parent, that is visible (your scene or other visible parent), action will be started right after object appear.

Morion
  • 10,495
  • 1
  • 24
  • 33
  • I am lost, how do I control where the object moves? How do I do it with this specific VOID statement? – user2083920 Mar 25 '13 at 01:00
  • cannot understand what do you mean. it is no difference, will you do it inside void method or somewhere else. – Morion Mar 25 '13 at 10:12
0

You add [redMenu runAction:[CCMoveTo actionWithDuration:time position:place]]; (you choose time and position) at the end of your redafter1 function so when the parent method is eventually called by a method such as init your menu will move.

Remember you cannot move a CCMenuItemImage because it's locked to the CCMenu's position. You have to move the CCMenu itself.

Hope this was helpful.

oneiric
  • 71
  • 2