How to replace scenes when clicked on imageview in cocos2d-android - cocos2d-iphone

i have started to develope an game app using cocos2d-android game engine, til now had put 4 imageview and a background image to the scene1, now if clicked on 1st imageview it should navigate to the next scene, i googled and youtube for this but did not succeeded, and also there is no more sources for cocos2d android game engine.

Make your image as menuItem and change your scene on the click method of that menuItem as below
CCMenuItem menuItem1 = CCMenuItemImage.item("backbtn.png", "backbtn.png", this,
"onClickMenuItem");
then handle the onClick method of this menuItem as below
public void onClickMenuItem(Object menuItem) {
if (menuItem == menuItem1) {
CCDirector.sharedDirector().popScene();
}
}

Use CCMenu and CCMenuItemImage or CCMenuItemSprite. You can set method that will be called on menu item click.

Related

Can I change the button background color when the mouse is over the button?

I created a simple frame with a single wxbutton, will I be able to change the button background color when the mouse is over the button?
var name = Button1
class name = wxButton
If it's so can anyone explain to me how to do it step by step?
Have you tried to catch wxEVT_LEAVE_WINDOW and the wxEVT_ENTER_WINDOW from the Button (not your window) and change the Buttons Background colour within the called function?

I want to show menu when cursor hovers over pushbutton and close menu when cursor is moved away

I am using Qt on Ubuntu.
I have a menu on QPushButton. I want to show menu when cursor hovers over the QPushButton and close menu when cursor is moved away.
Showing a popup menu on "hover" event seems to violate the user experience, as users expect to see the popup when they click the button. This is called a menu button. If you really want to use hover event, you may subclass the QPushButton class and use its respective events. However if you would like to use a menu button, you can try this:
QMenu *menu = new QMenu();
QAction *testAction = new QAction("test menu item", this);
menu->addAction(testAction);
button->setMenu(menu);
Documentation on QPushButton::setMenu.
You have to implement your owen QPushButton. Let's start by checking the MouseMoveEvent to handle when the mouse hover the widget.
To check if the cursos pos is inside your widget:
void CustomPushButton::mousePressEvent(QMouseEvent *e) {
const QRect widgetRect = ui->followersWidget->geometry();
const QPoint mousePos = ui->followersWidget->mapFromGlobal(QCursor::pos()); // or e->pos()
if (widgetRect.contains(mousePos)) {
// Mouse inside the widget, lets show the menu
} else {
// Mouse outside the widget, if the menu is open, close it.
}
QWidget::mousePressEvent(e);
}
To show/hide the menu you could use the QMenu::popup(..), from Qt Doc:
Displays the menu so that the action atAction will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().

How to get back to the previous CCScene?

I have one CCScene, in which their is About us ICON. When I tap on it, goes to the next CCScene where the information to display.
Now, what happen
When I touch on the back option of the android phone, Game closed.
what I need
when I click the back, It takes me to the First CCscene, where the Icon of ABOUT us present.
What should I do for this ???
Solution : From what I solve
CCDirector.sharedDirector().popScene();
You can use the CCDirector to push scenes on top of running scenes.
Say you have scene1 and scene2 both instances of CCScene (or a subclass of CCScene) then when the user taps the about icon :
[[CCDirector sharedDirector] pushScene:scene2]; // Assuming scene1 is already running
when the user taps the back button :
[[CCDirector sharedDirector] popScene];
EDIT : According to your comment (and in java this time :)) :
public void onBackPressed() {
super.onBackPressed();
if(backPressFlag==1) {
CCDirector.sharedDirector().popScene();
}
}
And of course this will work only if you pushed the About scene with :
CCDirector.sharedDirector().pushScene(AboutScene.scene());
you can do in this way on clicking back button
CCDirector.sharedDirector().getRunningScene().removeAllChildren(true);
Now create new scene
sceneIndex--;
CCScene scene = CCScene.node();
scene.addChild(backAction());
CCDirector.sharedDirector().replaceScene(scene);
Here backAction() is same as in cocos examples

CCMenuItemImage isn't showing the selected state

The documentation for CCMenuItemImage doesn't actually say what it does.
There are quite a few subclass CCMenuItem.
I've inherited a project that's using it as a button.
CCMenuItem *start;
start = [CCMenuItemImage itemFromNormalImage:[self prefixedImage:#"start button.png"]
selectedImage:[self prefixedImage:#"start button selected.png"]
target:myTarget
selector:#selector(start:)];
It was using the same button for both states.
I modified it to have a different image for the selected state.
I was expecting/hoping that when I touch the item it will be highlighted, and when I release the button it will send my target action (which it does).
(aside: in iOS parlance, i know that highlighted and selected are two different things. But this library does not seem to have that difference.)
So:
Is it intended to use this "menu item" as a button?
When is the selected image of this menu item displayed?
How should I go about making it display as selected?
CCMenuItem is an abstract class from which all of the other menu items inherit so what you did there in the code is technically wrong.
On the other hand you could subclass CCMenuItem to make your own custom class (for example: you can't use a button and a label on it as a menu item, you have to use either the button itself and the label is on top..just for show, or use the label and the button below is...pointless)
Subclassing CCMenuItem and making your own class would fix that problem (i mean you could make a method that would take an image and a string and returns a button)
What you want to do there is this:
CCMenuItemImage *button= [CCMenuItemImage itemFromNormalImage:#"start button.png"
selectedImage:#"start button selected.png"
target:self
selector:#selector(start:)];
CCMenu *start=[CCMenu menuWithItems:button,nil];
start.position=ccp(200,200);
[self addChild:start];
When you put your finger on the menu it will replace the normal image with the selected one, but will only activate of you release it in the boundingbox of the button (aka..you can press on the button, move your finger away from the button and it wont activate).
So in a sence the button is highlighted untill you release your finger, then its selected.
Did that answer your question?
Try this code...
CCMenuItemImage *backbtn = [CCMenuItemImage itemFromNormalImage:#"backbtn.png" selectedImage:#"backbtn_selected.png" target:self selector:#selector(LBback)];
CCMenu *Menu1 = [CCMenu menuWithItems:backbtn,nil];
[Menu1 alignItemsVerticallyWithPadding:15];
Menu1.position = ccp(160, 240);
[self addChild:Menu1];
By the help of this..when you touch on image is shows selected image other wise normal image...:)
and later when your function get called and you want to change its image then you can set like this..
[backbtn setNormalImage:[CCSprite spriteWithFile:#"backbtn_selected.png"]];
The code above is correct.
The image resource for selection was not added to the project, so was not being displayed. It may have output an error message on creation (buried in other output), but did not output error message when tapped.
The silent/safe failure made the user error harder to track down.

How to make popup image? wxWidgets

I'm trying to make a popup image preview window like it's done in Autodesk Revit Architecture:
The behaviour of popup image is:
When the mouse stops for 500 milliseconds over the truncated image, a full-sized popup image appears near the mouse cursor.
The Popup image is not a modal dialog, therefore controls of the main window(wxDialog) are still enabled.
The Popup window disappears on mouse movement.
I tried to do it, but i failed.
First I put wxStaticBitmap on wxDialog and use ShowModal() to show this full-sized image. It works great but as it's Modal, main window becomes disabled.
I tried to make this dialog not modal, but when I try to do it, main window raises(main window is modal) and image disappears.
upd.
Now my code:
class PictureFrame: public wxPopupTransientWindow
{
wxStaticBitmap *m_picture;
public:
PictureFrame( wxWindow *parent );
~PictureFrame();
};
Panel code structure is like this:
class MaterialsPane: public wxPanel
{
PictureFrame* m_popup;
wxTimer* m_timer;
public:
MaterialsPane( wxWindow* parent);
~MaterialsPane();
void OnTimer( wxTimerEvent& event);
void OnMouseMove( wxMouseEvent& event );
....
DECLARE_EVENT_TABLE()
};
Panel is placed in main modal dialog:
class MaterialsFrame: public wxDialog {
MaterialsPane* m_materialsPane;
public:
MaterialsFrame( wxWindow* parent, wxWindowID id = wxID_ANY);
~MaterialsFrame();
};
it helped but not completely. As image appears not under mouse cursor but near it (like in the picture of my question), popup window can't catch mouse movements. I tried to catch mouse movements in main dialog, but it failed, because focus is taken by popup window.
My goal is to close popup after any mouse movement.
You should post your code that 'fails'. It is hard to give specific advice when we have no information of what you are doing.
Have you looked at wxPopupWindow? http://docs.wxwidgets.org/trunk/classwx_popup_window.html
Personally, I find it easier to roll my own. Here's how the one I am working on right now looks
cNewDataPopup::cNewDataPopup( cPatDataset& data )
: wxDialog(NULL,-1,L"New data",wxPoint(200,200),wxSize(570,242),
wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP )
, myData( data )
{
...
Show();
}
To make this popup appear, simply call the constructor.
You would want to pass in your image to be displayed, store it in an attribute, handle the paint event by drawing your image on the client area.