2D Sprite movement question

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
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

2D Sprite movement question

Post by natol »

I am using the 2D tutorial and trying to implement movement with the keyboard based off of the movement turorial

Here is my sprite code:

Code: Select all

driver->draw2DImage(sprite1, core::position2d<s32>(270,105),
            core::rect<s32>(0,4,28,36), 0,
            video::SColor(255,255,255,255), true);
in the movement tutorial you create

scene::ISceneNode* node = 0;

at the beginning and then in the even receiver you call upon node

how would I use this code with the above sprite?

or could someone give me an example.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

the simplest way to do this is something like:

Code: Select all

driver->draw2DImage(sprite1, core::position2d<s32>( spritex ,105),
            core::rect<s32>(0,4,28,36), 0,
            video::SColor(255,255,255,255), true);
then to move left...

Code: Select all

spritex -= 1;
or right...

Code: Select all

spritex += 1;
you're probably best off reading a book on game programming though, i'm guessing this would be page 1 in most books.
Guest

Post by Guest »

I understand that to move an object you would use the

spritex.x -= 1;
s[rotex.x += 1;

my question is when I'm creating the even receiver how would I declare the variable for the sprite such as they did in the movement tutorial

Code: Select all

/*
In this tutorial, one of our goals is to move a scene node using some
keys on the keyboard. We store a pointer to the scene node we want to
move with the keys here.
The other pointer is a pointer to the Irrlicht Device, which we need
int the EventReceiver to manipulate the scene node and to get the 
active camera.
*/

scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
Then node is used for the event receiver.

so instead of scene::ISceneNode* node = 0 what would I use for a 2D sprite?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

hrm...
i spose you could try one of these instead then, since it inherits from ISceneNode
http://irrforge.org/index.php/Playing_2 ... h_Irrlicht
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

I just tried out that code and I get some errors

Code: Select all

12 C:\Data\irrlicht-0.10.0\examples\Sprite\sprite2test.cpp expected constructor, destructor, or type conversion before string constant 

12 C:\Data\irrlicht-0.10.0\examples\Sprite\sprite2test.cpp expected `,' or `;' before string constant 
this is on this line

Code: Select all

void main()
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

ooh... '#' was missing from the final #include. fixed now
Natol_guest

Post by Natol_guest »

thanks for the help I will try this out now
natol
Posts: 25
Joined: Fri Aug 13, 2004 5:12 pm
Location: USA, KS

Post by natol »

Now I get this error

Code: Select all

  [Linker error] undefined reference to `_imp___ZN3irr12createDeviceENS_5video13E_DRIVER_TYPEERKNS_4core11dimension2dIiEEjbbbPNS_14IEventReceiverEPKw' 
:(
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

yikes, i give up. try getting the 2d sprite code working on its own before adding your keyboard code.
since you didn't spot the missing # on the include line i'm guessing you're not reading it, and reading helps a lot!
Krypt
Posts: 4
Joined: Fri Jul 08, 2005 10:04 pm

Post by Krypt »

i get that same error krypt, trying to use devcpp while doing the hello world tutorial.
Post Reply