Update class redraws again?

Hello everyone !!
I have created a class, but when i “call” the Update method i can see a update but a certain ping-pong effect. What is the correct way to do this? My class inherits from LogicComponent and i draw a series of subnodes in OnNodeSet method, then in the Update method i only move the node that i have used in OnNodeSet. Thank you in advance !!

You don’t need to call the Update method yourself - it will get “ticked” by Urho3D every frame.
All objects deriving from Component will get “ticked” every frame.
To prevent this, you can disable individual components, their parent scene nodes, or entire scene node subtrees and all the components they hold - and in the latter case, there is a mechanism to undo such a change.

The component update method is not what you want for drawing stuff - it’s meant for logic updates, at full frame rate.

Stuff that you draw tends to derive from Drawable.

If you elaborate on what you’re trying to achieve, I might be able to help further - I’ve worked a lot with node hierarchies, including Urho’s scene hierarchy, and custom node hierarchies too.

Hope that’s helpful :slight_smile:

1 Like

Im trying to create a Tetris game, i have already created the clases for each Tetris figure, what im stuck is how to put all that logic in my app. For what i know in the update method i would like the figures to fall down from above of the screen i also need to make them move with keyboard keys, but as im so new in this everyday is a new begining for me. LOL

1 Like

I typically handle player input in my Update method, and depending on the user input, I do some kind of logic to control the player. Update method is called every graphics frame, as fast as the engine can render, unless the framerate is being capped (default cap is 200fps).

More rarely, I sometimes deal with player input in the FixedUpdate method… this one is not called every graphics frame (whose rate can vary!), instead it is “called from” the physicsworld component (via urho3d engine events) at a fixed rate.
It depends on the game, but since I figure you have no physics yet, the Update method would be the place to do it…

Sample.inl is included by all samples to handle common single key events (like take screenshot).
https://github.com/urho3d/Urho3D/blob/master/Source/Samples/Sample.inl#L92
https://github.com/urho3d/Urho3D/blob/master/Source/Samples/Sample.inl#L245

More sophisticated samples like NinjaSnowWar and CharacterDemo also do constant input polling with Input::GetKeyDown() and others from class Input.

Character::controls_ holds the control states like keys and mouse buttons down.
The app clears and sets these states on normal Update event: https://github.com/urho3d/Urho3D/blob/master/Source/Samples/18_CharacterDemo/CharacterDemo.cpp#L258

Character has subscribed to FixedUpdate ( with the LogicComponent SetUpdateEventMask(USE_FIXEDUPDATE) in Start() ) where it is continually acting on those.
https://github.com/urho3d/Urho3D/blob/master/Source/Samples/18_CharacterDemo/Character.cpp#L84

Hope that helps – let us know how it is going!

Offtopic @codefive: I never met a language I did not like. :slight_smile: (non-programming language :laughing:)

@jmiller Thank you !!
Yes !! I was looking right now at the CharacterDemo sample, and i think i will do something based on that, i already knew i needed some globals to hold my Class “sprite” or figure and also the controls so i can link both, but i wasnt shure how to do that, i will try and tell you how it goes. It isnt that i dont like Spanish, not at all, but when you are talking with friends and topics you really like, sometimes makes me wish i knew English native. Hugs to eveyone my friends !!

1 Like

So this is what i did, i added a rigid body, and linked to the keys the figures like

subNode_->Translate(Vector3::LEFT * 0.2f);

for the left movement and

subNode_->Translate(Vector3::RIGHT * 0.2f);

for the right movement, however i cant succed to move it down, perhaps i can add some gravity ? or why doesnt Vector3::DOWN seem to work ? Thank you again :slight_smile:

Use deltaTime to calculate your movement. The code above will result in different movement speed on various computers (lower fps slower movement and vice versa).
Also be aware that Translate() is performed in local space by default.

Then will SetPosition would be a better solution?

When using rigid bodies it’s better to apply forces to them instead of moving the nodes directly. This should happen during the FixedUpdate(float timeStep) of your Component using functions like:

  • RigidBody::ApplyForce(newtonsVec3 * timeStep)
  • RigidBody::ApplyImpulse(newtonsVec3)
  • RigidBody::ApplyTorque(newtonsVec3 * timeStep)
  • RigidBody::ApplyTorqueImpulse(newtonsVec3)
1 Like

Furthermore there are several functions available to control passive slowing of your rigid bodies like:

  • RigidBody::SetLinearDamping(float)
  • RigidBody::SetAngularDamping(float)
  • RigidBody::SetFriction(float)
  • RigidBody::SetRollingFriction(float)
  • RigidBody::SetRestitution(float)

Just use Translate(delta * deltaTime , TS_WORLD) when you need world coords. (If you want to apply gravity , etc).

1 Like

Oh such a precious information, and those constants TS_WORLD and such as what name i cant find them in Urho documentation? Are more like those? I think now im starting to understand

We don’t yet support SpinningFriction…

I never read the documentation because i found it useless. Well in some rare situations when i need some info about materials or techniques etc. But for simple things like this is usually use intellisense (VS) which gives me enough information about a function/class/enum once i type in my -> or . operator. Or i just type in / click a variable/function/enum and the code definition window opens the file and scrolls to the definition of the enum/class/function. Very useful and convenient feature. Way faster than searching hundreds of pages of documentation which will give you the same information as opening the file… since Urho3d uses Doxygen.

I wish Dave! I remember the “good old days of msvc” - lol!

Back on CodeBlocks, this time on Linux.
There’s some kind of bug that forces me to turn off symbolic lookups, otherwise the entire editor runs at a snail pace. This means I don’t get debug info from external libs, like Urho3D. Makes life interesting.

I dont want to tell what to do to a programming guru as you @Leith but i find Netbeans IDE very good, especially version 11, i like it even better than Eclipse, intellisense very good and very few bugs.

1 Like

Yep its nice to have options.
I probably should look further into them.

I did not like the Linux version of microsoft’s crossplatform “Code” IDE, I had used CodeBlocks previously on Windows, so I was already familiar with that IDE.

CodeBlocks on Linux has a lot of problems I could talk about, I am constantly closing and restarting it during my development day.

I know what you are saying, i have it also installed here at my Linux and i never use it, i dont know if it would be silly from my part to say that i even like more SublimeText3 if i have to decide now between the two. But lots of people like code i think it has many bugs, but i dont want to throw dirt here.

Could anybody help me to apply a Rigidbody to a node that has 3 sub-nodes ? When i try to do it i make the Engine crash :frowning: Well infact it crashes when i add a ApplyImpulse to that rigid body, and i dont know why