Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Irrlicht] Poruszanie Bitmapą za pomocą strzałek

Ostatnio zmodyfikowano 2014-08-18 14:39
Autor Wiadomość
wojownik266
Temat założony przez niniejszego użytkownika
[Irrlicht] Poruszanie Bitmapą za pomocą strzałek
» 2014-08-17 18:48:56
Jak zrobić w Irrlichcie przesuwanie bitmapy za pomocą strzałek? Pytam ponieważ większość kursów omawia przesuwanie obiektów 3d a mnie chodzi o zwykłe zdjęcie 2D.
P-115646
wojownik266
Temat założony przez niniejszego użytkownika
» 2014-08-18 14:39:09
Nurtujący mnie problem rozwiązałem w sposób następujący:

C/C++
#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace video;

class MyEventReceiver
    : public IEventReceiver
{
public:
    // This is the one method that we have to implement
    virtual bool OnEvent( const SEvent & event )
    {
        // Remember whether each key is down or up
        if( event.EventType == irr::EET_KEY_INPUT_EVENT )
             KeyIsDown[ event.KeyInput.Key ] = event.KeyInput.PressedDown;
       
        return false;
    }
   
    // This is used to check whether a key is being held down
    virtual bool IsKeyDown( EKEY_CODE keyCode ) const
    {
        return KeyIsDown[ keyCode ];
    }
   
    MyEventReceiver()
    {
        for( u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i )
             KeyIsDown[ i ] = false;
       
    }
   
private:
    // We use this array to store the current state of each key
    bool KeyIsDown[ KEY_KEY_CODES_COUNT ];
};

int main()
{
    float x = 320, y = 240;
    // create device
    MyEventReceiver receiver;
    IrrlichtDevice * device = createDevice( EDT_OPENGL, dimension2d < u32 >( 640, 480 ), 16,
    false, false, false, & receiver );
   
    if( !device )
         return 1;
   
    IVideoDriver * driver = device->getVideoDriver();
    ITexture * image = driver->getTexture( "ziel.png" );
   
    while( device->run() )
    {
        /* if(receiver.IsKeyDown(irr::KEY_KEY_W))
        y+=0.5f;
        else if(receiver.IsKeyDown(irr::KEY_KEY_S))
        y-=0.5f;*/
       
        if( receiver.IsKeyDown( irr::KEY_LEFT ) )
             x -= 0.5f;
        else if( receiver.IsKeyDown( irr::KEY_RIGHT ) )
             x += 0.5f;
       
        driver->beginScene( true, true, SColor( 255, 255, 255, 255 ) );
       
        driver->draw2DImage( image, position2d < s32 >( x, y ), rect < s32 >( 0, 0, 64, 48 ), 0, SColor( 255, 255, 255, 255 ), true );
       
        driver->endScene();
    }
   
    device->drop();
   
    return 0;
}
P-115675
« 1 »
  Strona 1 z 1