Fix element at zoom on Phaser3 - phaser-framework

How to fix an element at one point, despite the zoom? setScrollFactor(x [, y]) doesn't hepl me.
I have a moving element behind which the camera is moving. But I need to keep the button always in the right corner
Thanks for the fast reply)

create a separate scene specifically for the element that you want to remain static
in Phaser 3 multiple scenes can exist at the same time, and they have their own cameras (at least one main camera per scene), which allows you to have scene A with a moving camera rendering the game world, and scene B with a static camera rendering the UI

Related

How do I make sure that all changes are not discarded after the animation? Godot

After playing the animation several times, the object resets all movements and rotations(3d mode) each time and remains in one place. How do I make sure that all changes are not discarded after the animation?
Changes are not discarded after the animation. Period.
However, changes are reset when the animation starts again.
If you don't want the animation to change a property, don't include it in the animation. Or, put another way, if you don't want to reset a property, don't play an animation that includes it.
If you want the motion of the animation to be relative, you can animate a child node. For instance, you can have a physics body player character (e.g. RigidBody or KinematicBody), and then as a child have the model that represents it… And animate with AnimationPlayer the model, no the physics body. That way, the animation will reset the model to its parent (the physics body), but will not reset the physics body itself.
If you need finer granularity over what you track, consider using sub-properties. I have an explanation in another answer. It could be that animation is not the right tool for what you are doing. Consider using Tween, for example.
By the way, if you want to smoothly interpolate between animation, you can increase the animation blend time (which is 0 by default). I talk about that in yet a different answer.

Godot debug window not triggering area2d signals

Video of what's happening exactly
Specs are:
Display being recorded 2560x1080#60hz
Display that the window goes offscreen 3840x2160#24hz (tested with 60hz too)
Windows 10
GPU Nvidia 970 GTX
Just started learning godot this week and lost hours to this strange behavior.
Godot specifics:
Scale of shapes and bodies are not modified (not to mess with physics)
Starting out trying to create an Entity class, that extends KinematicBody2D, to create instances of enemies within my game. Just using the dummy block for now to test if collisions are indeed working (stopped here due to what happened on the video)
The big dummy square that has one square texture is said Entity, with a collision with huge Y size just to test things out.
The area2d I want to trigger the signal is the small rectangle in front of the character.
Is there something I should know that is causing the signal to only fire while the debug window is on the other display? Should I just move the debug window to the other display and trust the game will work?
Code snippets
Creation of Area2D inside my animation controller
func _create_shape_with_collision(s : Shape2D, parentNode : Node) -> Node:
var ret = Area2D.new()
ret.connect('body_entered', self, '_check_body_entered')
var c = CollisionShape2D.new()
c.shape = s
parentNode.add_child(ret)
c.disabled = true
c.name = 'collision_shape'
ret.add_child(c)
return ret
signal function
func _check_body_entered(body : Node):
print(body.name)
PS: Attempted to type some stuff to help with autocomplete within Godot's interface, but my created classes were not working properly.
PS2: posted this same message on godot's reddit page, in hopes of better visibility
Make sure you have a matching Collision layer and mask in the Area2D node.
Shape2D is a resource, meaning if you don't create .new() then all CollisionShape2D are using the same instance of the shape. If anyone sets explicitly it free it's gone for everyone (so try printing if you accidentally are assigning a null shape). There's some weirdness on resizing after assigning not happening when CollisionShape2D is ready.
But also you have c.disabled = true that probably shouldn't be there.
Because #Theraot laid a path towards writing an issue on Godot's Github page, I was able to determine the cause of the above bug, while creating a minimal project.
In fact, it does not relate at all with the code, but on project settings. The physics FPS was set at 60, while my secondary screen was able to capture the event, as VSYNC was also on by default (caps FPS at refresh rate, secondary screen is 24hz).
Increasing the physics FPS to 120 (empyrical at this point) made the signal work on all displays.
Will gladly accept a better answer, explaining what are the impacts of changing such number (the strain on devices etc), if it is a bad practice or if there is another way to configure individual faster ticks for Area2Ds or PhysicsBody2Ds. Could not write such answer due to my current lack of knowledge/research. Trying to write it at this point would be a sophism.
Since i'm just coding some basic game elements while writing a Game Design Document, it's so far so good for me.
Edit:
After an insight from user #Theraot, I overlooked how different _process and _physics_process worked; For my use case, most of what I was doing should be inside _physics_process, so I could revert the engine's physics FPS back to default value.

Flip horizontally and vertically single frames of an animated sprite

I have 4 (0-3 animation frames) different images of a coin animation with differet states of it spinning. I would like to make it look like its spinning by adding another 2 frames (4-5) to make it look like it spins. In current situation it looks like the coin spins 180 degrees and goes back to it's original position. I would like to flip vertically ONLY the 4th and 5th frame. How can i achieve that without making new redundant pngs?
I know making 2 new pngs is not a big deal in this case, but if i had more frames, and/or bigger sprites it could make a significant difference in future projects.
I was thinking you could make the animation flip horizontally when it reaches the last fame, however that would mean you would have to omit #4 and #5 to avoid duplicates, but it still would look odd because frame #3 would skip directly back to frame #0. I tried thinking of different orders the sprite frames could be placed in to clean this up, but all my solutions either result in duplicate frames, or ugly skips. Maybe you might be able to solve what I couldn't.
Unfortunately, it seems that though Godot supports play_backwards functionality for the animation_player node, there is no such feature when it comes to animated_sprite. Too bad, because this would likely solve your problem.
For now, I think your best bet is to do what you were trying to avoid.. flip the sprite images yourself and add them as animation frames, or make a separate animation containing the flipped sprites and have them switch back and forth after their last frames, respectively. It might be a lot of work for super large projects, but without some kind of play_backwards functionality for animated sprites, I don't think it's worth breaking your back trying to find a workaround this time.
Of course, if I am wrong, I would welcome any correction from the community.
Good luck.
this is one way to accomplish the task.
Inside the ready function of godot write
#used to store frame value
var frame = 0
Inside the function that your using that runs every frame write:
frame += 1
#resets the value representing the current frame
if frame > 5:
frame = 0
if frame == 4 || frame == 5:
#this should be whatever function you use to flip the sprite vetically
flip_h = true
else:
#this should be whatever function you se to flip the sprite horizontally
flip_h = false
You probably already know this because I recognize the udemy course this screenshot is from, as I am doing it right now, and this is explained later in the course (when adding spikeman enemy). But for those who don't know it can be solved by adding an AnimationPlayer and adding new animation track that deals with animation flip_h property of AnimatedSprite. Then you have to set flip_h on those last 2 duplicated frames.
You could use the signals to detect when the animation has finished

Fixed user interface elements for cardboard

I want create fixed user interface elements like "time remaining until the end of the level".
time remaining element
How should I make it to show it correctly in stereo camera
What you want is called non-diegetic UI and is a bit of an antipattern. The recommended way of doing this is to do a diegetic UI - something that is positioned somewhere in the scene, preferably on something that would make sense in real life - for example a computer screen on a console that is in sight.
Still, if you want something in a forced location, it will work well. To do this you should render it in 3d and rotate/position it so that it's always in front of your camera. For example if you would be using the Unity game engine, you could create this UI element as a world space canvas and parent it to the main camera.

How to disable body bouncing back in phaser?

I have a player and a coin. The coin moves towards the player at 400 per pixel, when it collides with the player the player is thrown back. How can I make the player stand still as if nothing had occurred? I tried setting immovable property to player but no result.
Sounds like you want game.physics.arcade.overlap instead of collide. collide will try and separate your sprites; overlap will just let you know that they touched. If you don't do anything in your overlap callback then the sprites will pass right through each other.
I use overlap a lot more than I use collide.

Resources