If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
scarface
Posts: 5 Joined: Sun Jun 11, 2006 7:34 am
Post
by scarface » Sun Jun 11, 2006 7:38 am
My code:
Code: Select all
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_S:
{
core::vector3df v = cow->getPosition();
v.Y -=2.0f;
cow->setPosition(v);
}
case KEY_KEY_Z:
{
core::vector3df v = cow->getPosition();
v.Y +=2.0f;
cow->setPosition(v);
}
case KEY_KEY_Q:
{
core::vector3df v = cow->getPosition();
v.X -=2.0f;
cow->setPosition(v);
}
case KEY_KEY_D:
{
core::vector3df v = cow->getPosition();
v.X +=2.0f;
cow->setPosition(v);
}
//return true;
}
}
Negative movements don't work (left/down), why?
Thanks.
vitek
Bug Slayer
Posts: 3919 Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR
Post
by vitek » Sun Jun 11, 2006 9:09 am
Because you forgot to break out of the case blocks. If you press S, cases S, Z, Q and D would be executed and nothing would happen. If you just press Z then Z, Q and D would be executed and the object would be moved up.
Travis
cadue
Posts: 72 Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano
Post
by cadue » Sun Jun 11, 2006 9:10 am
excusme, you know how the switch work? you've forgot the "break" at the end of the "case". this is corret:
Code: Select all
if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_S:
{
core::vector3df v = cow->getPosition();
v.Y -=2.0f;
cow->setPosition(v);
break;
}
case KEY_KEY_Z:
{
core::vector3df v = cow->getPosition();
v.Y +=2.0f;
cow->setPosition(v);
break;
}
case KEY_KEY_Q:
{
core::vector3df v = cow->getPosition();
v.X -=2.0f;
cow->setPosition(v);
break;
}
case KEY_KEY_D:
{
core::vector3df v = cow->getPosition();
v.X +=2.0f;
cow->setPosition(v);
break;
}
//return true;
}
}
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
cadue
Posts: 72 Joined: Mon Mar 13, 2006 8:33 pm
Location: Italy - Friuli - Monfalcone - Staranzano
Post
by cadue » Sun Jun 11, 2006 9:12 am
we've posted the message in the same moment!
excuse me for my bad english and for my ignorance...but I'm 14 and i come from Italy, where the study of english is a optional (-:
Baal Cadar
Posts: 377 Joined: Fri Oct 28, 2005 10:28 am
Contact:
Post
by Baal Cadar » Sun Jun 11, 2006 9:29 am
The code is also very repetitive. Better style:
Code: Select all
core::vector3df delta();
if (event.KeyInput.Key == KEY_KEY_S)
delta.Y = -2.0f;
else if (event.KeyInput.Key == KEY_KEY_Z)
delta.Y = 2.0f;
else if (event.KeyInput.Key == KEY_KEY_Q)
delta.X = -2.0f;
else if (event.KeyInput.Key == KEY_KEY_D)
delta.X = 2.0f;
cow->setPosition(cow->getPosition() + delta);
No offense
scarface
Posts: 5 Joined: Sun Jun 11, 2006 7:34 am
Post
by scarface » Sun Jun 11, 2006 9:36 am
I understand, thanks
vitek
Bug Slayer
Posts: 3919 Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR
Post
by vitek » Sun Jun 11, 2006 9:42 am
The code is also very repetitive. Better style:...
Well, except yours wouldn't compile [core::vector3df delta() would seen as a function declaration].
Baal Cadar
Posts: 377 Joined: Fri Oct 28, 2005 10:28 am
Contact:
Post
by Baal Cadar » Sun Jun 11, 2006 10:12 am
Yes. make it core::vector3df delta; then.
No offense