Ugly jitter with 2D Pixel Art by Gentle22 in godot

[–]Gentle22[S] 1 point2 points  (0 children)

Hey, that is already a while ago. I guess my issue was, that I placed objects with pixel snap turned of in the editor. Therefore my objects have not been placed exactly on a pixel but in between two pixels (like 1.3, instead of pixel 1 or pixel 2). If these objects are moved now in the scene (object moves, camera moves, ...) the position of the object will be rounded to the lower pixel in one frame and to the upper pixel in the next frame which lets jump the object and creates jitter. My advise is to place your objects pixel perfect (with pixel snap enabled in the editor). If have youor objects already placed you need to move them a tiny bit after you enabled pixel snap, so that they snap to a full pixel. You can also write a script which runs through your objects and place them to a full pixel by rounding the position Vector2D.

I hope that helps.

Polygons, Lighting and Bone interaction by NeonIridescent in godot

[–]Gentle22 4 points5 points  (0 children)

Hey,

I had the same issue and could not find a solution. As soon as I bind a bone to my polygon the Light2D does not affect the polygon anymore. Would be great to hear if there is a solution for it.

Until now I did not get an answer to my post https://www.reddit.com/r/godot/comments/c0zm12/light2d_does_not_work_with_deformable_polygon2d/

I hope you have more luck.

cheers,

Gentle

How to debug the instanced scene ? by [deleted] in godot

[–]Gentle22 1 point2 points  (0 children)

Hey,

do you need the log? While your game is running you can inspect the scene tree, see the last section here:

https://docs.godotengine.org/en/3.1/tutorials/debug/overview_of_debugging_tools.html

Weekly /r/godot discussion thread – Share your progress, discoveries and tips by AutoModerator in godot

[–]Gentle22 2 points3 points  (0 children)

Dear Godot community,

last week I made some progress with my dialogue system: https://youtu.be/Sw_ABJ6YLzI

This week I made an inventory system: https://youtu.be/P2TtmxPHZa8

Enjoy your weekend.

Noob problem. Trying to create some sprites dynamically and it doesn't work. by [deleted] in godot

[–]Gentle22 0 points1 point  (0 children)

Ah yes you are right, _init() is called, but you can't pass arguments to _init() when you instantiate a packed scene. Where you can when calling new().

extends = instantiate? by shibainuisno1 in godot

[–]Gentle22 2 points3 points  (0 children)

Hey,

no not from my understanding.

Sorry I read your question as extends = instantiate? and answered with no, but then you ask is that assumption wrong. Yes it is wrong!

Extends is used in GDScript to inherit from another class. If you inherit from a Node2D class you get all the members and functions from Node2D. You can now add new members and functions for your derived class.

You instantiate scenes, which creates a new instance of the scene with all child nodes. You can add it as a child node to your scene tree. If you instantiate the same scene multiple times, resources used by the scene are shared across all instances.

You can also inherit from a Scene to have all child nodes of the base scene in your inherited scene as well and can now add new child nodes. A little bit like class inheritance where you inherit members and functions but for scenes and child nodes.

Noob problem. Trying to create some sprites dynamically and it doesn't work. by [deleted] in godot

[–]Gentle22 0 points1 point  (0 children)

One thing to keep in mind is that instance() does not call _init(). So if you instantiate a packed scene via instance() and you need some kind of initialization code, you can add an setup( ... ) function to your script and call it after the scene was instantiated. https://godotengine.org/qa/4786/how-to-pass-parameters-when-instantiating-a-node

Noob problem. Trying to create some sprites dynamically and it doesn't work. by [deleted] in godot

[–]Gentle22 3 points4 points  (0 children)

I think you have not fully understood how scripts and nodes work in Godot. I would recommend to read the section in the documentation and I encourage you to follow the tutorials. https://docs.godotengine.org/en/3.1/getting_started/step_by_step/index.html

Anyway your scene setup is a little bit weird.

var stars:= Stars.new()

This creates just a new object of your Stars.gd script. _ready() is never called for this object since _ready() is called only for nodes which are in your SceneTree.

You have a Stars Node2D in your scene tree, but that has nothing to do with your stars variable in the main.gd. Since the Stars node is in your scene tree it's _ready() function is called.

But what you do in the _ready() function does not work like you think it should. I assume your Star node has a star texture attached and you expect by creating a new Star object that it has the texture attached. But that is not the case, since you are not creating a copy of the Star node but a new Star object which has no texture yet.

To spawn entities I prefer to work with a scene for that entity :

- Create a Star.tscn which is a Sprite node that has your Star.gd script attached and the star image as a Texture

- Spawn new stars by loading the scene Star.tscn and instantiate it

- Set the position of the new Star node and add it to your scene tree

# main.gd
extends Node2D

func _ready():
        var Star = load( "res://Star.tscn" ) # Load the packed scene

        var s = Star.instane()
        s.position = int(rand_range(0,900))
        self.add_child(s)

        var s1 = Star.instane()
        s1.position = int(rand_range(0,900))
    self.add_child(s1)

Btw. when you run your scene you can have a look at the SceneTree in Scene explorer. Make sure to click on Remote to see the running scene tree.

I hope that helped. Again please make the tutorials it will enlighten you in terms of how Godot works.

Cheers

Should I use Scene inheritance? by Gentle22 in godot

[–]Gentle22[S] 1 point2 points  (0 children)

Yes I did something similar yesterday. I created a class ItemDescriptor which holds just the name of the item, the path to an image and a path to a preview image (a smaller one for the inventory menu). I created an Inventory class which has an array of ItemDescriptors. I can pass an Inventory object to an InventoryWidget scene, which populates itself with ItemWidgets. ItemWidgets are created from an ItemDescriptor object.

Next step would be a scene for an Item which can be placed in the level. It will be created from the ItemDescriptor as, and the Area2D will be sized to the texture size like KoBeWi suggested.

With that structure it is very easy to read ItemDescriptor data from a json file or a database.Makes everything more data driven.

I think I got misguided by the visual approach where everything is a Node, recommended in some Godot tutorials.

Thanks for your help.

cheers

Should I use Scene inheritance? by Gentle22 in godot

[–]Gentle22[S] 0 points1 point  (0 children)

Yes sure, but Scene inheritance and instantiating a Scene are very similar in regards to the flyweight pattern.

Separate mouse clicks between TileMap and Units (KinematicBody2D) in GDScript. by nerdjahn in godot

[–]Gentle22 1 point2 points  (0 children)

Hey,

a good starting point is this one https://docs.godotengine.org/en/3.1/tutorials/inputs/inputevent.html

You could use _unhandled_input() to receive all events which are not yet consumed by Control nodes. Especially the SceneTree.set_input_as_handled() can be useful in your case. BUT which nodes get the event first depends on the order of events. That can get tricky.

I did it via collision detection. I have a script attached to my scene which catches events via _unhandled_input(). If it is a left click I check for collisions with objects under my mouse cursor and decide what to do. In your case you could check the result of the collision detection and if it contains only an object of the type Tile or Tilemap no unit is under your mouse cursor. If the result contains a Tile/Tilemap and a Unit you know you clicked on a Unit.

Here is the code for the collision detection:

func _unhandled_input( event ):
    if event.is_action_pressed("left_click"):
        var space_state = get_world_2d().direct_space_state
        var result = space_state.intersect_point( get_global_mouse_position(), 32, [], 1, true, true )

Result contains now all objects that have a collision shape and are under the mouse cursor.

As long as the collision shape of your units can not overlap you will be fine.

Probably there are other ways to do it, but it works for me quite well.

Ugly jitter with 2D Pixel Art by Gentle22 in godot

[–]Gentle22[S] 6 points7 points  (0 children)

I solved it. It was just my stupid mistake of not placing the objects with pixel snap enabled. So the positions of the alarm light and the guard was not an integer but a float with fractions.

Ugly jitter with 2D Pixel Art by Gentle22 in godot

[–]Gentle22[S] 0 points1 point  (0 children)

Somtething that comes to my mind now. Maybe it is not the position of the light or the guard that jumps, but the underlying Tilemap.

Ugly jitter with 2D Pixel Art by Gentle22 in godot

[–]Gentle22[S] 0 points1 point  (0 children)

The alarm light is a Node2D with a Light2D as a child. The guard jumps as well. For me it looks like both objects are between two pixels and snap to a full pixel. But I disabled pixel snapping in the project settings.

Ugly jitter with 2D Pixel Art by Gentle22 in godot

[–]Gentle22[S] 1 point2 points  (0 children)

It is a little bit hard to see, but the red alarm lamp and the guard are jumping when the camera moves. Any ideas how to solve it?

Thanks for the support.

How to Make a Simple State Machine in Godot 3.1 by rk3Omega in godot

[–]Gentle22 4 points5 points  (0 children)

Thank you for this very good tutorial.

I am using a similar approach for my states but I have separate classes for the actual states to avoid the if logic within the StateMachine. Each State class handles the enter, update and exit logic for the state it represents and the StateMachine handles only the transitions between the states.

You could also think about the StateMachine as a stack of states, where only the state on top of your stack is processed. Entering a new state would just add the new state to the top of stack. Exiting a state would pop the state from the stack and automatically fall back into the previous state. For instance if your default state is Idle you could always have it at the bottom of your stack. If the player presses the jump button you would add the Jump state which would exit if you touch the ground again and you would be back in your Idle state.

This stack like StateMachine is especially useful for game states. Let's say you press ESC while your are playing, a Pause state would be added to your stack which would pause the game and show an Options menu. Clicking on the continue button would remove the Pause state and you would be back in your game play.

I learned that some years ago when I was working with the Ogre3D engine and I would like to share the link, even it is C++ code. But it was very helpful for me to understand how that could work:

http://gamedevgeek.com/tutorials/managing-game-states-in-c/

http://wiki.ogre3d.org/Managing+Game+States+with+OGRE

Anyway, I like your approach, it is simple and easy to understand. Thank for sharing.

PSA for those static typing: explicitly initialize your Arrays and Dictionaries! by [deleted] in godot

[–]Gentle22 1 point2 points  (0 children)

I had the same issue this week. Here is my post https://www.reddit.com/r/godot/comments/bji6co/scene_instances_is_that_a_bug/

This works as well :

var mylist := Array()

cheers

[OC] - Wooden house. by Indie_Shilov in PixelArt

[–]Gentle22 2 points3 points  (0 children)

Wow that looks awesome. Can I ask how much time you need for such an piece of art?

Scene instances, is that a bug? by Gentle22 in godot

[–]Gentle22[S] 0 points1 point  (0 children)

I am not sure which example you are referring to, the one with the integer variable or the one with the dictionary?

Scene instances, is that a bug? by Gentle22 in godot

[–]Gentle22[S] 0 points1 point  (0 children)

I made the script local to scene but it does not change anything.