New problem. Have tried to solve few days... Well anyway i have tried to get my node to move when i press 'W'. Nothing happens when i press it. Code...:
Whoops, i was stupid. Thought this moves only 1 px(?) per every hit. And i dont have a clue how could i get it to move all the time when W, in this case, is pressed down. Help me
You can use the bool keys[] method, or you can simply create a global bool, set it to true when your key is pressed, then in the main device loop, if that bool is true, move the player. Keep in mind, both methods will move the player 1 point each loop, which varies greatly among computers, best to timestamp it and have it move a speed (points per millisecond).
I should've tried even few minutes to solve it, because after i posted, i tried to remove that ! before event.KeyInput.PressedDown. It worked, lol
Thanks for zeno60, i think i'll try that method too, for practice.
I guess i talked too soon. Got it work now, but i only can move forward & backward. I type :
"v.X += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;" for those and the same style for left and right, but i dont know how i should replace those 2.0f and -2.0f. I've tried like 0,0-2.0f and stuff but not working. Or is the problem somewhere else? Heres the code for what i've tried...
Normally you would put a break after each block of a switch statement. This keeps the execution path from 'falling through' to the next case in the switch.
In your case it makes more sense to just return...
switch(event.KeyInput.Key)
{
case KEY_KEY_S:
case KEY_KEY_W:
{
vector3df v = node->getPosition();
v.X += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true; //<-- added
case KEY_KEY_A:
case KEY_KEY_D:
{
vector3df a = node->getPosition();
a.Z += event.KeyInput.Key == KEY_KEY_A ? 2.0f : -2.0f;
node->setPosition(a);
}
return true;
}
I think i have had to Case breaks right. Im soo desperated, i dont have a clue. I feel that i should stop trying and think for a new hobby...
Maybe. I'd suggest that you take some time to learn a little bit about C/C++ before you go trying to write a full blown program with it. You may find this to be a bit of help.