I am developing simple windows phone 8 application. I want to play a song in it so after clicking on play button song should play and the image on play button should change to pause button.clicking on pause song should pause and images change to play button.. How to change the images?
You can consider to have two buttons one with play image and the other with the pause image and switch the visibilty of the buttons depending upon your needs, like when the song is not playing display the button with play image and when the song is playing collapse the play button and make the pause button visible. This not the solution you want to know just another way of doing it for your the solution you seek i'll need to know how you are setting the image on the play button.
Edit
there's a visibilty property in every control, by default the visibilty of a button is set to "Visible", if your buttons are named controls then you can access the buttons from your "code behind" in your click or tap events for the respective buttons
Suppose here the XAML for your buttons
<Button x:Name="PlayButton" Click="PlayButton_Click" Visibility="Visible"/>
<Button x:Name="PauseButton" Click="Pause_Click" Visibility="Collapsed"/>
Here is the code behind for the events attched
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
PlayButton.Visibility = Visibility.Collapsed; //Collapse the Play Button
PauseButton.Visibility = Visibility.Visible; // Make Pause Button visible
/*your code for play here*/
}
private void Pause_Click(object sender, RoutedEventArgs e)
{
PlayButton.Visibility = Visibility.Visible; //Make Play Button Visible
PauseButton.Visibility = Visibility.Collapsed; //Collapse Pause Button
/*your code for pause here*/
}
Try this. It helps you
<Image Source="Your play button source" MouseLeftButtonUp="imgPlayPause_MouseLeftButtonUp" x:Name="imgPlayPause"/>
In code behind take a global vaiable
bool IsPlay = false;
private void imgPlayPause_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if(!IsPlay)
{
IsPlay = true;
imgPlayPause.Source = Your Pause image source
//Set Bitmap Image as Image Source
plyaSong functionality
}
else
{
IsPlay = false;
imgPlayPause.Source = Your play image source
//Set Bitmap Image as Image Source
pause song functionality
}
}
Related
I am making an 2d Android game with libGDX.
In my play screen if a person just click the screen, my game character jumps.
Now, I added a pause image in my play screen.
When I test this, I saw that if I click pause image, the game character first jump. And after that the game is paused.
But I don't want this, I want that if I click pause image, don't jump , only pause the game. How can I do that ?
This is my update method of my playScreen class :
#Override
public void update(float dt) {
pauseImg.addListener(new ClickListener() { // I think, these lines work after.
public void clicked(InputEvent event, float x, float y) {
isPaused=true; //if pause image clicked,the game will be paused
}
});
if(isPaused==false){ I think these lines work firstly.
if (Gdx.input.justTouched()) {
bird.jump();
}
}
.
.
.
}
You don't need to add pauseImg listener every frame you can just do it in create() method.
If you will i think this should work.
I have created an imageButton with three drawable images;
one is button-up,button-down and button checked.Its purpose is to ON and OFF sound for the game.once sound is OFF,checked image should be displayed.
I have written the code like this:
soundButton = new ImageButton(new TextureRegionDrawable(soundTexture1),
new TextureRegionDrawable(soundTexture2), new TextureRegionDrawable(soundTexture3));
stage.addActor(soundButton);
soundButton.setPosition(Constants.WORLD_WIDTH / 4 + 300f, Constants.WORLD_HEIGHT / 4, Align.bottomLeft);
soundButton.addListener(new ChangeListener(){
#Override
public void changed(ChangeEvent event, Actor actor) {
if(!game.soundBool)
game.soundBool=true;
else
game.soundBool=false;
}
});
Here soundBool is initially false and game sounds will play when it is false.
once I make it true,sounds should not play.This boolean is working well.
Problem is that once I checked the button(sound OFF) sound is getting OFF permanantly.Again Button click is not working as expected.
How do I change the code to work it well?
Have you checked how often the changed() method is called? Use Gdx.app.log() for logging. Or try using a different Listener, like ClickedListener for the button.
You could also make you own Button, class MyButton extends Button to keep a cleaner code. Here is how I solved it.
I'm currently developing an Universal Application, but here is a problem. I have a Frame with the TextBox for User Phone Number.
So, I want to change the height of my LayoutRoot (GRID) so it can fits in the free space.
I'm using InputPane.GetForCurrentView().Showing and InputPane.GetForCurrentView().Hiding for that purposes.
Here is my code.
public UserRegistrationAuthorization_PhoneNumber()
{
this.InitializeComponent();
LayoutRootInitialHeight = LayoutRoot.ActualHeight;
InputPane.GetForCurrentView().Showing += UserRegistrationAuthorization_PhoneNumber_Showing;
InputPane.GetForCurrentView().Hiding += UserRegistrationAuthorization_PhoneNumber_Hiding;
}
private void UserRegistrationAuthorization_PhoneNumber_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
LayoutRoot.Height = LayoutRoot.ActualHeight - args.OccludedRect.Height;
LayoutRoot.VerticalAlignment = VerticalAlignment.Top;
args.EnsuredFocusedElementInView = true;
}
private void UserRegistrationAuthorization_PhoneNumber_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
// TODO: Get rid of that shit
LayoutRoot.Height = LayoutRootInitialHeight;
args.EnsuredFocusedElementInView = false;
}
When I click outside the TextBox keyboard hides and leaves after that a black hole on the screen. 2
But, the most interesting is that when I press that physical Back Button on my Lumia, keyboard hides normally and my LayoutRoot gets the Frame's initial height.
Is it a bug or I'm doing something wrong?
It happens because by the time you saving your LayoutRootInitialHeight in the constructor, LayoutRoot actually isn't loaded and it's ActualHeight == 0. Then you setting LayoutRoot.Height to 0, so it becomes not visible. So you should probably save your LayoutRootInitialHeight in LayoutRoot's Loaded event handler.
I would also suggest you not to change LayoutRoot's height at all. It causes your whole visual tree to be rendered from scratch and it's bad practise in general. Instead, modify RenderTransform of all necessary elements so they get moved to appropriate positions. RenderTransform is the right way to handle movements and animations on the screen, and you can achieve some nice visual effects with Next button moving up same as keyboard.
Roughly your code can look like this:
<Button Content="Next" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center">
<Button.RenderTransform>
<CompositeTransform x:Name="NextButtonTransform" TranslateY="0"/>
</Button.RenderTransform>
</Button>
...
private void UserRegistrationAuthorization_PhoneNumber_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
{
NextButtonTransform.TranslateY = -300;
EnsuredFocusedElementInView = true;
}
private void UserRegistrationAuthorization_PhoneNumber_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
{
NextButtonTransform.TranslateY = 0;
args.EnsuredFocusedElementInView = false;
}
And more complicated way is to run some storyboard which makes your Next button move up and down in same speed with keyboard, always appearing on top of it. Although, since InputPane.GetForCurrentView().Showing gets fired after keyboard already shown fully, you should hook up all animations to TextBox.GotFocus and TextBox.LostFocus events. On mobile, keyboard is always shown when text box has focus, so it will work nicely.
I have a PhoneApplicationPage with some grids, images and a few buttons. If I tap outside my buttons, anywhere in the page (on an image, grid or whatever), I want to open a new page.
How can I detect a tap/click anywhere on the page?
I see at least two ways to do that:
Listen to the MouseLeftButtonUp event on your PhoneApplicationPage. It should be triggered by images and labels but not by buttons
Listen to the Tap event on your PhoneApplicationPage. However, this event will be triggered even when the user tap on a button. To prevent this, you can retrieve the list of controls at the tap coordinates in the event handler, and open the new page only if there's no button:
private void PhoneApplicationPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var element = (UIElement)sender;
var controls = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(element), element);
if(controls.OfType<Button>().Any())
{
return;
}
// Open the new page
}
How to get focus to a internal jframe inside a jframe when we show our applet on browser and applet start focus automatically go to browser arrow keys do page up and down no my specifiec order that i add to my frame listener?
Try this code:
protected void createFrame() {
MyInternalFrame frame = new MyInternalFrame();
frame.setVisible(true);
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}