Is there any way to set custom positions and rotations/angles for MenuItems in the menu?
Custom MenuItems positions/rotations
(6 posts) (3 voices)-
Posted 2 years ago #
-
Yes, you can treat the menu like any other Cocos node object. As an example, I have the following code for one button to return to a main menu, and I position it with setPosition:
returnMenu = [MenuItemImage itemFromNormalImage:@"main-menu.png" selectedImage:@"main-menu-pressed.png" target:self selector:@selector(returnToMainMenu:)]; helpMenu = [Menu menuWithItems:returnMenu, nil]; [helpMenu setPosition:ccp(90,30)]; [self addChild:helpMenu z:3];I'd imagine you could also apply all of the same other manipulations as well.
Posted 2 years ago # -
This code is for custom positioning menu, but my question is: can you custom position your menuitems in menu? Menu knows a simple vertical or horizontal items arrangement, but I want to custom position each of my menu items.
To do something like that:
//you have MenuItems item1,item2,...
menu = [Menu menuWithItems:item1,item2,nil];
[item1 setPosition: ccp(100,100)];
[item1 setRotation: 10];
[item2 setPosition ccp(200,200)];
[item2 setRotation: 25];
// ...
Let me explain further what i have tried already:
1. i tried to create a new menu for each of my items. This way i can set custom position for each of my one-item menu. But the problems are:
- You must raise your finger and press it again to activate other item/menu. This is because you can drag and choose between items only under the same menu.
- Having 5 one-item menus works really slow. I am getting a massive fps drop.2. I thought of rotating and displacing the source images (I use bitmap menu item and source png would be rotated/displaced). But this is also bad because the press area would not the same ass the visible part of the button.
Posted 2 years ago # -
My mistake!
Setting MenuItem position works just fine, but i didn't notice that in this case the position of MenuItem is RELATIVE to the menu position rather then ABSOLUTE because my values were too big and MenuItems where positioned off the screen. Seems logical now. Rotation and other stuff works as well.
Posted 2 years ago # -
Not working for me, can you give a whole piece of code where this is working ?
Posted 1 year ago # -
It started working for me after I deleted and rewrote my code, I guess I must have missed something before ?!
Posted 1 year ago #
Reply
You must log in to post.