Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 11, 2019, 4:52:57 PM (5 years ago)
Author:
mkarpf
Message:

getRadius added, example-level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/MouseAPI_FS19/src/modules/MouseAPI/mouseapiexample.cc

    r12296 r12302  
    1919    if(MouseAPI::isActive())
    2020        MouseAPI::getInstance().deactivate();
    21 
    2221}
    2322
    24 void MouseAPIExample::testfunction(MouseButtonCode::ByEnum mouse)
     23// change the size of the cube to a random number by clicking on it
     24void MouseAPIExample::changesizeonclick(MouseButtonCode::ByEnum mouse)
    2525{
    26     float randomnumber = (rand()%100 + 1)/20.0;
     26    // generate random number between 1 and 20
     27    float randomnumber = std::fmax((rand()%100 + 1)/20.0,1);
     28    // change the scale of the cube to this random number
    2729    this->setScale(randomnumber);
    28     orxout() << "Blah\n";
    29     //this->getGametype()->getPlayers().begin()->first->getControllableEntity()->mouseLook();//getCurrentCameraPosition()->setAllowMouseLook(false);
    30     //this->getGametype()->getPlayers().begin()->first->stopControl();
     30    // change the radius of the clickableObject to the new size
     31    MouseAPI::getInstance().changeRadiusOfClickableObject(cubeid,randomnumber);
     32}
    3133
     34// change the size of the sphere by scrolling on it
     35void MouseAPIExample::changesizeonscroll(int abs,int rel,const IntVector2& mousePos)
     36{
     37    // increase or decrease the size of the sphere
     38    this->setScale(1+rel);
    3239}
    3340
     
    3542{
    3643    SUPER(MouseAPIExample, XMLPort, xmlelement, mode);
     44    //todo: id xml-port
    3745    MouseAPI::getInstance().activate();
    38     MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->testfunction(mouse);});
    39     //this->getGametype()->getPlayers().begin()->first->getControllableEntity()->mouseLook();
    40 
     46    cubeid = MouseAPI::getInstance().addClickableObject(this->getWorldPosition(),10,std::list<MouseButtonCode::ByEnum>{MouseButtonCode::Left},[this](MouseButtonCode::ByEnum mouse){this->changesizeonclick(mouse);});
     47    //sphereid = MouseAPI::addScrollElement(this->getWorldPosition(), 10, [this](int abs, int rel, const IntVector2& mousePos){this->changesizeonscroll(abs,rel,mousePos);});
    4148
    4249}
Note: See TracChangeset for help on using the changeset viewer.