I currently have a Pause scene in which the animation is a closing door. (Added to the gameworld via add layer). If I choose resume, it will open up and resume the game.
I've also a Quit button in which player will go back to the game menu. I like the
effect to be when quit is selected the door will open to the game menu. How do I go about doing this?
I created the same animation onto the game menu. So when I replace scene the animation will
be played from the game menu.
Related
I download the character .fbx file from Mixamo and add to Unity. I want to get .anim file like
.
I try to drag Idle to the Animation window like, but it cannot paste in the Animation window.
I drag Idle to Animator and make a transition like, but when I test by drag character object to Animator and click the play button it not move.
you are not supposed to have 2 idle states. You should be able to make the idle animation in only one state. Like this 1:
Idle State
I think the problem of your animation is not about the format of the file. When you grab all the frames of your animation or just make it in unity, they will turn .anim file.
If you realize that when you play the game the state does not change from entry to Idle. You can try this:
Click on the animation you created, in the inspector and check if is loop is active 2.
Idle Inspector
Add an animator component in your character object3.
Animator
Create an animation controller [4].
[Create Animation Controller][4]
Drag and drop the animator controller in the controller component.
Open the animator and you should be able to drag your Idle animation to the animator tab where you were in. When you run once again your game you should be able to see the animation running.
Note: Some pictures I took are from unity2d, so probably it is not the perfectly the same inspector as yours, but you should be able to find it out. If you do not or if you still have any doubt, you can check this video. He exports it from blender, but the format .fbx is pretty the same. https://www.youtube.com/watch?v=D-oYgs1CP7U&ab_channel=SingleSaplingGames
I'm building an iOS game and I had the game set up to start whenever the user first touched the screen. This was working out perfectly fine for testing until I added menu buttons as an overlay that would disappear when the game starts. Obviously I can no longer just check for user input, because the game now starts even if I tap a UI button.
I tried adding an invisible UI panel with a box collider behind my UI buttons with an OnPointerDown that would start the game, but for some reason it was acting very inconsistent and would sometime require 5+ taps to start the game. It also wouldn't start if you tapped on the player because it would hit his collider instead.
Is there a better way to do this?
I have Spritekit game for the Mac. It includes NSMenuItems in the menu as with normal Mac applications. Now the thing is that
if I choose an action from the menu with the mouse, the Spritekit game starts executing right away and some of the subsequent animation is missed.
if I choose the same action with the keyboard shortcut, the game starts executing right away but none of the animation is missed since there is no delay switching from menu animation to game animation.
Is there some way to identify if the IBAction sent by the menu item is being triggered by the keyboard equivalent or by mouse? I want to add a start delay to the game animation if mouse is used and no delay for key equivalent.
The type of the current event can be obtained by reading NSApp.currentEvent.type.
See NSApp.currentEvent and NSEvent.type for details.
I've created a pong clone with the following:
Main Menu (New Game, Options, About, Quit).
Level1 (Able to press ESC which opens a pause menu panel (Resume Game, Options, Quit to Main Menu).
So far I've duplicated my Options Panel from the Main Menu scene, and pasted it in the Level1 scene. Is there a better way to do it? Can I call the Main Menu Options panel from my Level1 scene? I guess creating an Options prefab would be another idea?
I would like to get it sorted before I work on my options menu (Sound ON/OFF, Sound adjustable via slider, Music ON/OFF, Music adjustable via slider) - hopefully I can implement it so it covers all scenes.
This is in C# by the way, in Unity.
You can not change values in other scene directly as the instances do not exist at that moment but you can use PlayerPrefs to save data on exiting scene and at the loading of scene you can load that data in you UI.
For example you can save and load sound volume like this:
float mySoundVolume;
void OnDestroy(){
PlayerPrefs.SetFloat("SoundVolume", mySoundVolume);
}
void Awake(){
mySoundVolume = PlayerPrefs.GetFloat("SoundVolume");
applyValuesToUI();
}
You can read more about PlayerPrefs here. https://docs.unity3d.com/ScriptReference/PlayerPrefs.GetFloat.html
I have a game that I developed, and there are three scenes: the pause menu, the home screen menu, and the gameplay itself. During the gameplay, when the game is paused, it brings up the pause scene with:
[[CCDirector sharedDirector] pushScene:[PauseScene node]];
From the pause scene, there are three options: restart, resume, home menu. When clicking on resume it just pops the pause scene and goes back to the game scene to resume gameplay. When clicking on the home menu it keeps the gameplay scene in the background, and from the home menu screen, the gameplay is still running. So far, after much research, I have not been able to find a way to popScene (kick it out of the RAM pretty much) the gameplay scene from any scene but the gameplay scene. From the pause screen, I can use:
[[CCDirector sharedDirector] popScene];
to get rid of the pause scene, and if I run that code from a method on the gameplay scene, I can get rid of that instance of gameplay, but I need a way to popScene the gameplay node that is running in the background from the pause node. Overall, the basic question is: How can I pop a specific scene in Cocos2d from another scene?
There are two main features to change scenes in Cocos2d: pushScene/popScene and replaceScene.
The first is pushScene:
(void) pushScene: (CCScene *) scene
Suspends the execution of the running scene, pushing it on the stack
of suspended scenes. The new scene will be executed. Try to avoid big
stacks of pushed scenes to reduce memory allocation. ONLY call it if
there is a running scene.
This function utilizes a stack . It stores all the scenes in a Last In-First Out (LIFO) data structure. Basically it overlays the scenes and removes them in the reverse order of which they came. This is likely what you want to "push" (or bring up) the pause menu, and "pop" (remove) the pause scene back off to then resume gameplay.
To go back a layer, you simply call popScene:
(void) popScene
Pops out a scene from the queue. This scene will replace the running
one. The running scene will be deleted. If there are no more scenes in
the stack the execution is terminated. ONLY call it if there is a
running scene.
2.The other option, which I believe you will want, is replaceScene. This stops a currently running scene and replaces it with a completely new one. This is likely what you want for ending games or transitioning from the original main menu to the gameplay for the first time:
(void) replaceScene: (CCScene *) scene
Replaces the running scene with a new one. The running scene is
terminated. ONLY call it if there is a running scene
*Keep in mind: Use pushScene sparingly. It stores all of the scenes in memory so that they can later be popped of the stack. So don't store too many scenes and forget about them.
**Source: cocos2D website
EDIT 1:
You have a few options. Remember that replaceScene only replaces the currently running scene and is usually what you want to use. It does not "clear" the entire scene stack, so often you rarely want to use pushScene/popScene. In my demo below, I show you the issues with both. I do, however, try to conserve memory by when possible.
Using push/popScene:
1.Start running with the Home Screen.
2.When the user clicks "Play" button, use replaceScene to stop the Home Screen scene and start running the Game Play scene (keep in mind, Home Screen will no longer be running or saved anywhere in memory. if it has to remember any information, then save it to the stack with pushScene. The reason I do this is because the Home Screen will likely be the same each time and needs not continue to run while we play).
3.The user can now play for a bit. Then they want to pause for a bathroom break. They click a "Pause" button. Then use pushScene to save the current state of Game Play scene and begin running the Pause Menu scene. (Game Play is "paused" so to speak).
Your stack now looks like this:
//Bottom ----------------------> Top
[Game Play scene], [Pause Menu Scene]
4.After pausing for a bit, they could use pushScene to remove Pause Menu Scene from memory, and load the Game Play scene that is "paused" and resume play immediately.
The problem then becomes, well, what if you wanted to go from pause -> main menu. If you just used replaceScene on the Pause Menu, then the old game would linger in memory. You would need to find a way to purge that old Game Play scene.
The other option would have to be keeping Home Screen around by keeping it on the stack with a pushScene and then popping twice. This often causes "jumpy" transitions from my experience.
The preferred approach tends to be: create a Singleton Class and have that save the memory while you pause. (A Singleton Class is just a class that only ever has one instance. It is basically our "current game state" data. I recommend this tutorial.)
Using Replace Scene:
1.Start running with the Home Screen.
2.When the user clicks "Play" button, use replaceScene to stop the Home Screen scene and start running the Game Play scene (keep in mind, Home Screen will no longer be running or saved anywhere in memory. if it has to remember any information, then have a section of the Singleton Class for Home Screen data).
3.The user can now play for a bit. Then they want to pause for a bathroom break. They click a "Pause" button. Immediately "pause" your game and save all necessary sprites, game logic, etc to the Singleton Class, and then use replaceScene to quit from the Game Play scene and load Pause Scene. Then depending on their choice, you either continue play (step 4), or go to the Home Screen(step 5)
4.Reload everything necessary to render the game from the Singleton Class and replaceScene to quit from the Pause Menu and load up Game Play scene.
5.Use replaceScene to quit from the Pause Menu and load up the Home Screen.