工作总结3(随时修改)

工作总结3(随时修改),第1张

概述子d类: Bullet* Bullet::create(float attack, Vec2 startPos, Vec2 endPos){ Bullet* pRet = new Bullet(); pRet->_attack = attack; //攻击力 pRet->_startPos = startPos; //起点和终点 pRet->_endPos = endPos;

子d类:

Bullet* Bullet::create(float attack,Vec2 startPos,Vec2 endPos){	Bullet* pRet = new Bullet();	pRet->_attack = attack;     //攻击力	pRet->_startPos = startPos; //起点和终点	pRet->_endPos = endPos;	if (pRet && pRet->init())	{		pRet->autorelease();		return pRet;	}	else	{		delete pRet;		pRet = NulL;		return NulL;	}}

bool Bullet::init(){	if (!Layer::init())	{		return false;	}	Size visibleSize = Director::getInstance()->getVisibleSize();	_bullet = Sprite::create("pd/baizhanche.png");	Vec2 dtPos = _endPos - _startPos;	float rotation = CC_radians_TO_degrees(Vec2::angle(dtPos,Vec2(1,0))); //弧度转为角度,现在是点击点与起点和横轴的夹角                                                                       	if (dtPos.y > 0)   //点击的点在武将位置的上方		rotation = -rotation;
        float dt = _endPos.distance(_startPos);	_bullet->setRotation(_bullet->getRotation() + rotation);	this->setposition(_startPos);	_bullet->setposition(Vec2(0,0));	auto done = CallFuncN::create([=](Ref* ref)	{		this->removeFromParentAndCleanup(true);	});	this->runAction(Sequence::create(MoveBy::create(2,dtPos*(visibleSize.wIDth * 2 / dt)),done,NulL));	addChild(_bullet,0);	return true;}
Rect Bullet::getRect(){<span >	</span>Rect a = _bullet->getTextureRect();<span >	</span>float minX = this->getposition().x - a.getMaxX() * 0.5; //最左的边<span >	</span>float minY = this->getposition().y - a.getMaxY() * 0.5; //最下的边<span >	</span>Rect b = Rect(minX,minY,a.getMaxX(),a.getMaxY());<span >	</span>return b;}

另如果想实现匀速运动(因为Moveto MoveBy都是按照固定的时间来运动):

voID Bullet::kaihuo(Point pos){	float xdistance = (pos.x - this->getposition().x);	float ydistance = (pos.y - this->getposition().y);	_radii = atan2(ydistance,xdistance);	scheduleUpdate();}voID Bullet::update(float dt){	_time += dt;	this->setposition(Vec2(_pos.x + BulLETSPEED * _time * cos(_radii),_pos.y + BulLETSPEED * _time * sin(_radii)));}

另:

getBoundingBox 中得 Size.wIDth .height 显示图片真实大小 (考虑缩放和不缩放)
getContentSize 纹理图片大小
getTextureRect 当前的纹理在总纹理的位置 (不考虑 缩放不缩放)
图片有缩放 就用 getBoundingBox ,不考虑缩放用 getContentSize

总结

以上是内存溢出为你收集整理的工作总结3(随时修改)全部内容,希望文章能够帮你解决工作总结3(随时修改)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1033737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存