Making toggle MenuItem a sliding (ON/OFF) button with cocos2d-x - cocos2d-x

While using cocos2d-x got stuck with a problem. A toggle menu is made for sounds and music on-off switch. I want to make them draggable like in apple native ui they are. searched the net and even in the forum and documentation.

I think what you're looking for is CCControlSwitch.
CCSprite *onSprite = CCSprite::create("ui/switch-on.png");
CCSprite *offSprite = CCSprite::create("ui/switch-off.png");
CCSprite *thumbSprite = CCSprite::create("ui/switch-thumb.png");
CCSprite *maskSprite = CCSprite::create("ui/switch-mask.png");
CCControlSwitch *control = CCControlSwitch::create(maskSprite, onSprite, offSprite, thumbSprite, nullptr, nullptr);
control->setOn(status);
control->needsLayout();
control->addTargetWithActionForControlEvents(this, cccontrol_selector(DebugLayer::toggleShowStats),, CCControlEventValueChanged);
addChild(control);
There's an example in samples/Cpp/TestCpp/Classes/ExtensionsTest/ControlExtensionTest within your cocos2dx distro.
Hope it helps,
Laurent

Related

can't enable physics Debug Draw mode

i'm using cocos2dx 3.3 and i setDebugDrawMask looks like below
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
But nothing draw on my screen evenif there has many boxes.
Here is my code snippet for drawing debugNode for physics space. However it is written in js for Cocos2d-x-js, I hope it will help.
function initDebugMode(controller) {
var phDebugNode = cc.PhysicsDebugNode.create(space);
controller.addChild(phDebugNode, 10);
}
create your scene using below code
auto scene = Scene::createWithPhysics();
then go ahead and add features to your scene
scene->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
Hope this helps

move dynamic body object in box2d when touchbegin

I am creating a game like bounce ball using box2d in cocos2d-x. I created a dynamic body object and i want it to move when touch began. I am using the following code to move the dynamic body but it is not moving. Please anyone could help me to solve the problem.
bullet2=CCSprite::create("block.png");
bullet2->setPosition(ccp(2740, 1220));
this->addChild(bullet2,0);
ballBodyDefB.type=b2_dynamicBody;
ballBodyDefB.position.Set(2740/PTM_RATIO, 1170/PTM_RATIO);
ballBodyDefB.userData=bullet2;
ballBodyDefB.gravityScale=0;
_bullet=_world->CreateBody(&ballBodyDefB);
b2PolygonShape bulletshape;
bulletshape.SetAsBox(bullet2->getContentSize().width/PTM_RATIO/2,
bullet2->getContentSize().height/PTM_RATIO/2);
b2FixtureDef b_bullet ;
b_bullet.shape = &bulletshape;
b_bullet.density = 1.0f;
b_bullet.friction = 0.1f;
b_bullet.restitution = 0.0;
_bullet->CreateFixture(&b_bullet);
CCTouchbegan:
b2Vec2 force = b2Vec2(0, -450);
_block->ApplyLinearImpulse(force, _block->GetPosition());
Hi moving the sprite which follow b2body is easy. You need to attach Sprite to the b2body.userData and in box2d world step synchronize the position and rotation of your sprite with your b2body.
I can't answer directly your question, please post your code and what version of cocos2d-x you have for more details:
Check if your code contain code about: (depend on cocos2d-x version, you use CCSprite which is deprecated in 3.2, we use Sprite only anyway)
box2d world (you already have _world)
_world step iteration
syncing sprite position with b2body
Anyway you can find more details at these links:
http://www.cocos2d-x.org/wiki/Box2D and http://www.cocos2d-x.org/wiki/Getting_Started_with_Cocos2d-x

Content Transition Windows Phone

I have 2 viewboxes in my page and currently I am doing this:
ViewBox1.Visibility = Visibility.Collapsed;
ViewBox2.Visibility = Visibiltiy.Visible;
That means upon some button press, I am hiding first viewbox and showing the second one. Now, upon hiding I want a simple transition animation like viewbox1 sliding out and viewbox2 sliding in, something like this.
I have installed WPF toolkit, but can't figure this out.
Any help is highly appreciated.
Currently I have found this solution, this is actually full page transition but it works for me, I am sharing this code here:
SlideTransition transition = new SlideTransition();
transition.Mode = SlideTransitionMode.SlideLeftFadeIn;
PhoneApplicationPage page = (PhoneApplicationPage)((PhoneApplicationFrame)Application.Current.RootVisual).Content;
ITransition trans = transition.GetTransition(page);
trans.Completed += delegate
{
trans.Stop();
};
trans.Begin();

changing skins in flash as3

hello im making game and im trying to add skins for layers in this game so i made a vovieclip
and inside it there are skins http://prntscr.com/2as4mp and inside that when it be clicked there are http://prntscr.com/2as4pm i want it that when i ress this button the skin will change in the menu i tried this
select_2.addEventListener(MouseEvent.CLICK, open1243)
function open1243(event:MouseEvent){
bk = 1
gotoAndStop(2)
}
stop ();
well that dint work um where there is goandsto 2 that goes to menu thats it nothing works pls help
In your event listener, you're not specifying that you want select_2 to gotoAndStop, rather, it will apply that method call to whatever this is in the scope of that method. I'm guessing, at that point, it's the stage.
select_2.addEventListener(MouseEvent.CLICK, open1243);
function open1243(event:MouseEvent){
bk = 1
select_2.gotoAndStop(2);
}
You should probably make sure your event listener could be used for any object similar to select_2, in which case, I would suggest you change that line of code to:
MovieClip(event.target).gotoAndStop(2)

Windows Phone 8 ApplicationBar expanded unchangable transparancy

following Code...
<!--Navigation-Bar-->
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" ForegroundColor="White" IsMenuEnabled="True" BackgroundColor="#002B55">
<shell:ApplicationBarIconButton Click="B_Search_Click" IconUri="Images\Pic_Search.png" Text="Search"/>
<shell:ApplicationBarIconButton Click="B_Media_Click" IconUri="Images\Pic_Media.png" Text="Media"/>
<shell:ApplicationBarIconButton Click="B_Scan_Click" IconUri="Images\Pic_Scan.png" Text="Scanner"/>
<shell:ApplicationBarIconButton Click="B_Charts_Click" IconUri="Images\Pic_Charts.png" Text="Charts"/>
<shell:ApplicationBar.MenuItems>
<shell:ApplicationBarMenuItem Click="B_Logout_Click" Text="Logout"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
gives me following ApplicationBar...
http://s14.directupload.net/file/d/3341/4xiadbvz_jpg.htm
(Solid background when expanded)
BUT if I create the AppBar in CodeBehind like this...
private void ResetApplicationBar()
{
ApplicationBar = new ApplicationBar();
ApplicationBar.BackgroundColor = Color.FromArgb(150, 0, 43, 85);;
ApplicationBar.ForegroundColor = Colors.White;
ApplicationBar.Opacity = 1;
ApplicationBarIconButton B_Search = new ApplicationBarIconButton();
B_Search.IconUri = new Uri("/Images/Pic_Search.png", UriKind.Relative);
B_Search.Text = "search";
ApplicationBar.Buttons.Add(B_Search);
B_Search.Click += new EventHandler(B_Search_Click);
(more Buttons...)
then I get that misterios unchangable Transparency...
http://s1.directupload.net/file/d/3341/zjo57e37_jpg.htm
(Half-Transparent when expanded)
How can I change the Background to solid???
-Yes I have mostly overwritten the theme
-Changing global colors doesnt work
-changing background/foreground doesnt work
-changing opacity doesnt work...
I need to generate it from code behind because im changing it dynamically in one window
(or is it possible to define multiple AppBars in markup?)
Thanks in advance!
Please try this one
ApplicationBar.BackgroundColor = Color.FromArgb(52,0,2,181);
ApplicationBar.ForegroundColor = Colors.White;
You will get the same color in designer page by this way.
This (52,0,2,181) is the conversion value of #002B55
On a fresh project, everything seems fine, here.
"- changing background/foreground doesnt work
- changing opacity doesnt work..."
Using the Application Bar sample, you provided in XAML, but with Opacity=0.5, I get this :
After I click the "Change Color" button, which does ApplicationBar.Opacity = 1;, I get this result :
(The background image is slightly moved up, because in first case we provided an opacity and in the second there was none explicitly specified and it seems the app bar didn't layered over the image, but to fix this you can set an Opacity=0.999, close to 1).
It must have something to do with all the theme overwriting you have done or some customization you attempted.
If this isn't quite helpful, provide me more details and I'll try to help as I can.
Thank you very much for effort, but changing opacity didnt to 0.999 didnt help either.
I found a solution!! And its quite simple :)
I Just take the old bar instead of creating a new one:
//Old Code
ApplicationBar = new ApplicationBar();
//New Code
ApplicationBar.Buttons.Clear();
ApplicationBar.MenuItems.Clear();
Hope it helps someone!