Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2d-android CCMenu does not respond to touch
    primarykey
    data
    text
    <pre><code>import org.cocos2d.events.CCTouchDispatcher; import org.cocos2d.layers.CCColorLayer; import org.cocos2d.layers.CCLayer; import org.cocos2d.layers.CCScene; import org.cocos2d.menus.CCMenu; import org.cocos2d.menus.CCMenuItem; import org.cocos2d.menus.CCMenuItemImage; import org.cocos2d.nodes.CCDirector; import org.cocos2d.types.ccColor4B; import android.view.MotionEvent; public class MenuLayer extends CCColorLayer { public static CCScene scene() { // Create the scene CCScene scene = CCScene.node(); // Create a background layer. CCLayer background = new MenuLayer(ccColor4B.ccc4(255, 255, 255, 255)); scene.addChild(background); return scene; } protected MenuLayer(ccColor4B colour) { super(colour); // Create a menu items. CCMenuItem start = CCMenuItemImage.item("Start.png", "Start.png", this, "startTouched"); CCMenuItem options = CCMenuItemImage.item("Options.png", "Options.png", this, "optionsTouched"); CCMenuItem help = CCMenuItemImage.item("Help.png", "Help.png", this, "helpTouched"); // Create array of CCMenuItem object to add to CCMenu CCMenuItem[] items = { start, options, help }; // Add menu items to menu CCMenu menu = CCMenu.menu(items); // Align items with 150px adding menu.alignItemsVertically(150); // Add menu to the scene addChild(menu); CCTouchDispatcher.sharedDispatcher().addTargetedDelegate(this, 0, true); this.setIsTouchEnabled(true); } @Override public boolean ccTouchesBegan(MotionEvent event) { return true; } @Override public boolean ccTouchesEnded(MotionEvent event) { return super.ccTouchesEnded(event); } /**This method is called when the start menu item is touched**/ public void startTouched() { CCScene scene = GameLayer.scene(); CCDirector.sharedDirector().pushScene(scene); } /**This method is called when the options menu item is touched**/ public void optionsTouched() { CCScene scene = OptionsLayer.scene(); CCDirector.sharedDirector().replaceScene(scene); } /**This method is called when the help menu item is touched**/ public void helpTouched() { CCScene scene = HelpLayer.scene(); CCDirector.sharedDirector().replaceScene(scene); } } </code></pre> <p>I'm getting started with cocos2d-android and I'm having trouble getting a menu to respond to touch events.</p> <p>The scene loads up and runs okay it just won't respond to touch events. If I put a breakpoint in ccTouchesEnded I can intercept the event but startTouched, optionsTouched, and helpTouched are never called. As far as I have read, CCMenu should have this functionality built in.</p> <p>cocos2d-android is ported from cocos2d-iphone.</p> <p>Can anyone point me in the right direction? </p> <p>UPDATE:</p> <pre><code>07-21 13:31:17.933: WARN/System.err(6660): java.lang.NoSuchMethodException: startTouched 07-21 13:31:17.933: WARN/System.err(6660): at java.lang.ClassCache.findMethodByName(ClassCache.java:247) 07-21 13:31:17.933: WARN/System.err(6660): at java.lang.Class.getMethod(Class.java:962) 07-21 13:31:17.933: WARN/System.err(6660): at org.cocos2d.menus.CCMenuItem.&lt;init&gt; (CCMenuItem.java:54) ... // The errors repeat for optionsTouched and helpTouched </code></pre> <p>It looks like it not resolving the selector parameter to the correct method. Can anyone see anything wrong with startTouched or the others?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload