3D Model Creation//3d models
Auto model = sprite3d::create ("Sprite3dtest/boss1.obj");
Model->setscale (4);
Model->settexture ("Sprite3dtest/boss.png");
Model->setposition3d (VEC3 (S.WIDTH/2, S.HEIGHT/2, 0));
AddChild (model);
Eventlistenertouchonebyone Monitoring
eventlistenertouchonebyone* _lis = Eventlistenertouchonebyone::create ();
_lis->ontouchbegan= [This] (touch* t,event* e) {
Cclog ("Ontouchbegan");
return true;
};
_lis->ontouchmoved= [This] (touch* t,event* e) {
Cclog ("ontouchmoved");
float dx = T->getdelta (). x;
VEC3 rot = _camcontrolmode->getrotation3d ();
Rot.y + = DX;
_camcontrolmode->setrotation3d (ROT);
VEC3 Woldpos;
_camnode->getnodetoworldtransform (). Gettranslation (&woldpos);
Camera::getdefaultcamera ()->setposition3d (Woldpos);
Camera::getdefaultcamera ()->lookat (_camcontrolmode->getposition3d ());
};
director::getinstance ()->geteventdispatcher ()->addeventlistenerwithscenegraphpriority (_lis,this);
Add screen Listener, when tapping the screen, the sprite with the rotation of the movement
Helloworld::helloworld ()
{
Auto listener = eventlistenertouchonebyone::create ();
Listener->ontouchbegan = Cc_callback_2 (helloworld::ontouchbegan,this);
listener->ontouchended = Cc_callback_2 (helloworld::ontouchended,this);
_eventdispatcher->addeventlistenerwithscenegraphpriority (Listener,this);
Auto Sprite = sprite::create ("Images/grossini.png");
Auto layer = Layercolor::create (color4b (155,55,0,25));
AddChild (layer,-1);
AddChild (Sprite,0,ktagsprite);
Sprite->setposition (20,150);
Sprite->runaction (Jumpto::create (4,VEC2 (300,48), 100,4));
Layer->runaction (Repeatforever::create (Sequence::create (fadein::create (1), fadeout::create (1), nullptr));
}
BOOL Helloworld::ontouchbegan (touch* touch,event* Event)
{
return true;
}
void helloworld::ontouchended (touch* touch,event* Event)
{
Auto location = Touch->getlocation ();
Auto s = Getchildbytag (Ktagsprite);
S->stopallactions ();
S->runaction (Moveto::create (1,VEC2 (LOCATION.X,LOCATION.Y)));
Float o = location.x-s->getposition (). x;
float a = Location.y-s->getposition (). Y;
Float at = (float) cc_radians_to_degrees (atanf (o/a));//Anti-ATANF
if (a <0)
{
if (o<0)
{
at = +-fabs (at);
}else
{
at = 180-fabs (at);
}
}
S->runaction (Rotateto::create (1,at));
}
Create a 3D model/Add a screen listener, and when you tap the screen, the sprite moves with rotation