2D Motion.

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.
Post Reply
Nosvera2
Posts: 16
Joined: Wed May 28, 2008 3:11 am
Location: Van Buren, Arkansas

2D Motion.

Post by Nosvera2 »

Can anyone give me some code snippets of how to make ITextures move? I used the code below thinking it would work but it doesn't. Any help would be appreciated.


ITexture* Character = 0;
IrrlichtDevice* device = 0;
int myspeed = 2;
int start_x = 200;
int start_y = 200;
int mypos_x = start_x; //This is the 'X' coordinate.
int mypos_y = start_y; //This is the 'Y' coordinate.

class CharacterControl : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (Character != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_A:
{
mypos_x -= myspeed;
}
return true;
case KEY_KEY_D:
{
mypos_x += myspeed;
}
return true;
case KEY_KEY_W:
{
mypos_y -= myspeed;
}
return true;
case KEY_KEY_S:
{
mypos_y += myspeed;
}
return true;
}
}

return false;
}
};

*Then, I use then in main to create and draw the 2D texture.

ITexture* mychar = driver->getTexture("ninja.bmp");
driver->makeColorKeyTexture(mychar, core::position2d<s32>(mypos_x,mypos_y));

while(device->run() && driver)
if(device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,255,255,255));
smgr->drawAll();
driver->draw2DImage(map, core::position2d<s32>(0,0),
core::rect<s32>(0,0,640,400), 0,
video::SColor(255,255,255,255), true);
driver->draw2DImage(mychar, core::position2d<s32>(mypos_x,mypos_y),
core::rect<s32>(0,0,18,24), 0,
video::SColor(255,255,255,255), true); //I draw it at mypos_x and mypos_y and alter the coordinates with the event detector thinking it will redraw it when the event detector goes off. Is there something I need to add here?
guienv->drawAll();

driver->endScene();
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

so what happens? Are you sure that your event receiver is working, i.e. are the variables changing?
Post Reply