DrawNode* rect = DrawNode::create();
//rect->setAnchorPoint(Point(1,1));//这里个值没有用
rect->drawRect(Point(0,0),Point(100,100),Color4F(255,255,100));//这里的默认anchorpoint值为0
//rect->drawRect(Point(300,300),Point(200,200),100));
//rect->setPosition(Point(100,100));//设置其位置
this->addChild(rect,1);
//Sprite* sp1 = Sprite::create();
//sp1->setTexture("menu_background.jpg");
//Sprite* sp1 = Sprite::create("menu_background.jpg");
//auto bath = SpriteBatchNode::create("Hello.png");
//Sprite* sp1 = Sprite::createWithTexture(bath->getTexture());
//根据缓存plist中的sprite frame来创建,这种用的比较多
//SpriteBatchNode* node = SpriteBatchNode::create("Hello.png");
//Sprite* sp1 = Sprite::createWithTexture(node->getTexture());
Sprite* sp1 = Sprite::createWithSpriteFrame(SpriteFrame::create("Hello.png",Rect(0,480,320)));
sp1->setAnchorPoint(Point(0,0));
//sp1->setPosition(Point(10,10));
sp1->setTag(100);
this->addChild(sp1,0);
schedule(schedule_selector(SpriteTest::callback),10);//调用时间
return true;
}
void SpriteTest::callback(float dt) { Sprite* sp1 = (Sprite*)this->getChildByTag(100); sp1->setTexture("HelloWorld.png"); sp1->setPosition(100,100); sp1->setRotation(-90);//这里的旋转没有时间设置而是直接到位的 }
原文链接:https://www.f2er.com/cocos2dx/339483.html