Page 1 of 1

Key Action Help

Posted: Sun Dec 23, 2007 5:18 pm
by M.Irr
hi,
i've a little problem. I am going to make a FSPShooter and I think i understand the basics of Irrlicht. But I want to make a action when i Press a Key. Then I want that this:

Code: Select all

node = smgr->addLightSceneNode(0, core::vector3df(0,0,0), 
		video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
	scene::ISceneNodeAnimator* anim = 0;
	anim = smgr->createFlyStraightAnimator(
		core::vector3df(camera->getPosition().X,camera->getPosition().Y,camera->getPosition().Z),
		core::vector3df(
		(cos((camera->getRotation().X)*(3,141592654/180))*100+camera->getPosition().X),
		(sin((camera->getRotation().Y)*(3,141592654/180))*100+camera->getPosition().Y),
		0),250.0f,true);
	node->addAnimator(anim);
	anim->drop();

	// attach billboard to light

	node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(50, 50));
	node->setMaterialFlag(video::EMF_LIGHTING, false);
	node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
	node->setMaterialTexture(0,	driver->getTexture("../../media/particlewhite.bmp"));
runs.
But how could I make that my problem is that the variables and other object got create in the main class and I think the event receiver must be write before that. Please Help me.
M.Irr

PS:My english is really terrible I know.

Posted: Tue Dec 25, 2007 11:24 am
by M.Irr
nobody? :(

Posted: Tue Dec 25, 2007 11:50 am
by hybrid
If you want to avoid global variables (which is a good idea - avoiding it) you can add methods to set some pointers in the event reciever once those objects are created. After all, the EventReceiver is just a class like all others, and you can add as many methods and member variables as you want.
Or you only do the event handling in the receiver, and pass back some values which is handled in your main loop. Depends on how you want to separate game logic and rendering.

Posted: Tue Dec 25, 2007 11:56 am
by M.Irr
my idea is a variable who is set to true when the key is pressed but how could i do a variable for all classes?

Posted: Tue Dec 25, 2007 1:53 pm
by hybrid
Static class members use one instance for all objects. But is that really what you want?

Posted: Tue Dec 25, 2007 4:47 pm
by M.Irr
sorry I am a Beginner an your words are a little bit difficult to understand. I am coding very long with different programms but c is new the biggest problem is that I am German and 14 years so my english is not very good at the moment. Coul you post a little code example how you make things like that :?: Thanks for the fast help!!!! :D

Posted: Tue Dec 25, 2007 7:11 pm
by hybrid
Just go through one or two tutorials on C++, or even better buy a good book. It will give you not just one single feature, but the full view. That's far better than hoping to get through with just those few things you already new about C++.
For making a class member static simply prefix it with the keyword static. The initialiser for that variable will be only called once in the first object, all other assignments done later on will be reflected as usual.