How can I add text like "Game is paused" when I pause the game in GameMakerStudio2 - game-engine

I have a code to when I press "p" the game pauses. Although, I want to show some text saying like "Game is Paused. Press P to progress" how can I do that? HereĀ“s my code:
//create event
pause=false;
pauseSurf=-1;
pauseSurfBuffer=-1;
resW=1920;
resH=1080;
//Post-Draw event
gpu_set_blendenable(false);
if(pause)
{
surface_set_target(application_surface);
if(surface_exists(pauseSurf)) draw_surface(pauseSurf,0,0);
else // restore from buffer if we lost the surface
{
pauseSurf = surface_create(resW,resH);
buffer_set_surface(pauseSurfBuffer,pauseSurf,0);
}
surface_reset_target();
}
if(keyboard_check_pressed(ord("P")))// Toggle pause(Whatever condition/trigger you like)
{
if(!pause)// pause now
{
pause=true;
// deactivate everything other than this instance
instance_deactivate_all(true);
// NOTE:
// If you need to pause anything like animating sprites,tiles,room backgrounds
// you need to do that separately,unfortunately!
// capture this game moment(won't capture draw gui contents though)
pauseSurf=surface_create(resW,resH);
surface_set_target(pauseSurf);
draw_surface(application_surface,0,0);
surface_reset_target();
// Back up this surface toabuffer in case we lose it(screen focus,etc)
if(buffer_exists(pauseSurfBuffer)) buffer_delete(pauseSurfBuffer);
pauseSurfBuffer=buffer_create(resW*resH*4,buffer_fixed,1);
buffer_get_surface(pauseSurfBuffer,pauseSurf,0);
}
else // unpause now
{
pause=false;
instance_activate_all();
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
}
}
gpu_set_blendenable(true);
//Clean up event
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
Code from: https://www.youtube.com/watch?v=dNiLIX8jNOM&t=95s&ab_channel=ShaunSpalding
If any of you knows how to help me I would be thankful! :)

Add a DrawGui Event to your object, and then add the following code within:
if (pause)
{
draw_text(50, 50, "Game is Paused. Press P to progress");
}
DrawGui makes it so that it renders on top of your viewport, so it's not connected with the position in the room.
The 50, 50, is the X and Y position of the text, use it as you see fit. You can use it centered if you take the width/height of the camera/viewport and divide that by 2.
The pause is already defined in the Create Event, so that shouldn't give any problems.

Related

Windows Phone 8.1 Action Center like page design

I am trying to move an object in a page form top to down on user finger movement using translate transform. we should see page contents as the bar goes down the page and sits at bottom.
Just like Action Center in windows phone 8.1.
Please let me know any ideas how we can design. Thanks.
Good question!
My first thought was to do something like this.
You could get the touch input location and then move a rectangle from the top of the screen and translate it down according to they Y Cord of the Touch Input.
EDIT:
Okay so here is what you can do.
Create a Canvas and position it somewhere at the top ( i gave it the height of 14 in collapsed state).
Then create a private void cn_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) event and make it set the height of the Canvas. I also included a float i to later make it snap back or cover the entire screen if the user lets go during the pull-event.
private void cn_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
{
cn.Height += e.DeltaManipulation.Translation.Y;
i = (float)e.CumulativeManipulation.Translation.Y;
}
And thats it. You can also add this event to make it snap back or go cover the full screen when the user lets go.
private void cn_ManipulationCompleted(object sender, System.Windows.Input.ManipulationCompletedEventArgs e)
{
if(i < 100)
{
cn.Height = 14;
}
else
{
cn.Height = Application.Current.Host.Content.ActualHeight;
}
}
Of course you can add smoother animations so it slowly goes back into the collapsed view or fills the entire page.
I hope this helps!

animation for zoom in and zoom out in android for imageview

How do i set zoom in and zoom out when click on imageview?I want my program to react when user click on imageview must get large to some extent and can move imageview on that screen and sometime it reduce the size along when it move on touch anywhere on the screen .when click again is go resume original size what do i do?
As far as I know there are two ways.
The first way:
Make a new folder in res called 'anim'. Than make a xml file inside, for example zoomin.xml. Afterwards put the following code inside.
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:toXScale="5"
android:fromYScale="1"
android:toYScale="5"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>
Make another one for zoom out, but with reversed values.
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="5"
android:toXScale="1"
android:fromYScale="5"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"
android:fillAfter="true">
</scale>
You can change the values according to your needs. I think that they are self-explanatory.
And now in your java code.
ImageView imageView = (imageView)findViewById(R.id.yourImageViewId);
Animation zoomin = AnimationUtils.loadAnimation(this, R.anim.zoomin);
Animation zoomout = AnimationUtils.loadAnimation(this, R.anim.zoomout);
imageView.setAnimation(zoomin);
imageView.setAnimation(zoomout);
Now you only need to keep track which is the current state. And for each state execute this lines of codes:
imageView.startAnimation(zoomin);
and
imageView.startAnimation(zoomout);
For example:
imageView.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
if(!pressed) {
v.startAnimation(zoomin);
pressed = !pressed;
} else {
v.startAnimation(zoomout);
pressed = !pressed;
}
}
});
The other way is described here : http://developer.android.com/training/animation/zoom.html.
You can make this by following this guide easily
http://developer.android.com/training/animation/zoom.html
shortly you should use third imageview which is invisible when the user touches any imageview you want, you can display it by using animation in the imageview which is invisible.

Thumbnail of previous image instead of cancel button while camera is open

i want to show the thumbnail of the previous image taken by camera instead of the cancel button while camera is running ...
Is that possible ?? Need help ..
Yep. Just capture the last image, keep it in memory (or save it to disk), then use it as one of the controls. We can do this using the overlay property of the Titanium.Media.showCamera function. Here is a quick example:
First we need an overlay view to show the image.
var overlayView = Ti.UI.createView();
var imageView = Ti.UI.createImageView({
width:44,
height:44,
left : 5
});
overlayView.add(imageView);
Now this is the function we use to open the camera with the overlay view. Note that we don't have controls so you need to add those (for closing etc). All we do right now is set the overlays image.
Titanium.Media.showCamera({
success:function(event) {
// called when media returned from the camera
imageView.image = event.media;
},
cancel:function() {},
error:function(error) {},
saveToPhotoGallery:true,
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
overlay : overlayView,
showControls: false // This is important!
});
To really make this work, you may need to save the event.media in a global variable, or use a similiar technique make sure overlayView will not be nulled out / garbage collected.
Also this is a barebones solution, not very robust, but this is the basic method I would use!

How to detect a click on a form reset button from QtWebKit?

Looking at the signals in the QtWebKit API, I failed to find anything that would seem to me to be what I am looking for.
QWebView
linkClicked() seems to be the closest, but a reset button is no link, and definitely does not point to an URL.
QWebPage
I considered the following signals (judging by their name), but according to their description none of them match my purpose either: contentsChanged(), contentsChanged(), contentsChanged(), selectionChanged().
QWebFrame
None of its signals matches my purpose.
QWebElement
Here I can see how to get an object representing the button(s), but it has no signals whatsoever.
I want to catch a click in a reset button in order to store the data in the form before it gets cleared, so it can be restored later.
For now, I did manage to retrieve the buttons as a QWebElementCollection of QWebElement objects, and I can modify them, but I do not know how to get them to send a signal upon click, or something similar.
// Get reset buttons.
QWebElementCollection inputResets = mainFrame()->documentElement().findAll("input[type=reset]");
inputResets += mainFrame()->documentElement().findAll("button[type=reset]");
// Change their text (just a test).
foreach(QWebElement element, inputResets)
{
element.setPlainText("Worked!");
}
Well, I got it working with this, although I do not think it is the best approach:
bool EventFilter::eventFilter(QObject* object, QEvent* event)
{
if (event->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::LeftButton)
{
QWebView *view = dynamic_cast<QWebView*>(object);
QPoint pos = view->mapFromGlobal(mouseEvent->globalPos());
QWebFrame *frame = view->page()->frameAt(mouseEvent->pos());
if (frame != NULL)
{
// Get the existing reset buttons.
QWebElementCollection inputResets = frame->documentElement().findAll("input[type=reset]");
inputResets += frame->documentElement().findAll("button[type=reset]");
// Check if any of them is at the clicked position.
foreach(QWebElement element, inputResets)
{
if (element.geometry().contains(pos))
{
qDebug() << "Clicked element tag:" << element.localName();
return QObject::eventFilter(object, event);
}
}
}
}
}
return QObject::eventFilter(object, event);
}
You can probably accomplish this with Qt WebKit Bridge.

Empty UITapGestureRecognizer buffer

I'm trying to design a really simple card game. The functionality basically consists on discovering the cards in order just tapping on them. To do this I put the cards on a UIView, and I overlay other UIView where I capture the taps. Then I just calculate which card has been tapped and I flip it.
The problem is that if I tap a wrong card, this tap appears to remain in a kind of buffer, and when I tap another card, sometimes a previous card tapped flips without being tapped. Is this buffer real or I'm doing something else wrong? If this buffer is real, how can I delete its content every time I capture a new tap?
Thanks in advance.
Problem solved :)
Here is the part of the code where the problem was, between
tapping the card and checking if it is a king.
[...] some code here [...]
// And if what we have found is a king, then we uncover the next card in the game stack and .
if ([[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardValue] == 9) {
//[self uncoverTheNextCardToPlay];
do {
[self uncoverTheNextCardToPlay];
} while ([[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardValue] == 9 && gameWindow.lastIndex < 40);
}
// And we update the realIndex with the real index index of the card just uncovered.
gameWindow.realIndex = ([[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardSuit]*10)+[[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardValue];
[...] more code here [...]
- (void)uncoverTheNextCardToPlay
{
gameWindow.lastIndex = gameWindow.lastIndex+10;
[[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] setCover:NO];
[[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] refreshCardWithCardBack:gameWindow.cardBack];
gameWindow.realIndex = ([[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardSuit]*10)+[[gameWindow.deck getCardAtIndex:gameWindow.lastIndex] cardValue];
}