通过cocos2d 的代码
Block.h的代码
#include <iostream>
#include<cocos2d.h>
USING_NS_CC;
class Block:public Sprite
{
public:
virtual bool init();
virtual void update(float dt);
CREATE_FUNC(Block);
};
Block.cpp代码
#include "Block.h"
bool Block::init()
{
Sprite::init();
Size s = Size((rand()%20)+5,(rand()%30)+10);
Size visibleSize = Director::getInstance()->getVisibleSize();
setPhysicsBody(PhysicsBody::createBox(s));
setTextureRect(Rect(0, 0, s.width, s.height));
setContentSize(s);
setPositionX(visibleSize.width);
scheduleUpdate();
return true;
}
void Block::update(float dt)
{
this->setPositionX(getPositionX()-1);
if(getPositionX()<0)
{
log(">>>");
unscheduleUpdate();
removeFromParent();
}
}
这个案例中block虚函数怎样实现动态联编!
|
|