![]() |
| ラーメンもホカホカ! |
![]() |
| もう怒ったぞ! |
![]() |
| ラーメンもホカホカ! |
![]() |
| もう怒ったぞ! |
#ifndef SPRINGMOVE_H_
#define SPRINGMOVE_H_
#include "cocos2d.h"
class CC_DLL SpringMoveBy : public cocos2d::ActionInterval
{
public:
static SpringMoveBy* create(float duration, const cocos2d::Vec2& position, float mass, float k);
//
// Overrides
//
virtual SpringMoveBy* clone() const override;
virtual SpringMoveBy* reverse(void) const override;
virtual void startWithTarget(cocos2d::Node *target) override;
/**
* @param time In seconds.
*/
virtual void update(float time) override;
CC_CONSTRUCTOR_ACCESS:
SpringMoveBy() {}
virtual ~SpringMoveBy() {}
/**
* initializes the action
* @param duration in seconds
*/
bool initWithDuration(float duration, const cocos2d::Vec2& position, float mass, float k);
protected:
cocos2d::Vec2 _startPosition;
cocos2d::Vec2 _delta;
float _k;
float _mass;
cocos2d::Vec2 _previousPos;
float _velocity;
float _accel;
float _position;
private:
CC_DISALLOW_COPY_AND_ASSIGN(SpringMoveBy);
};
#endif /* SPRINGMOVE_H_ */
#include "SpringMove.h"
USING_NS_CC;
//
// SpringMoveBy
//
#define GRAVITY 9.80665 // 重力加速度
#define NATURAL_LENGTH 0 // 自然長
#define FIRST_ACCEL GRAVITY // 初期加速度
#define FIRST_VEROCITY 60 // 初期速度
#define FIRST_POSITION 0 // 初期位置
#define FRICTION 0.996 // 摩擦係数
USING_NS_CC;
SpringMoveBy* SpringMoveBy::create(float duration, const Vec2& position, float mass, float k)
{
SpringMoveBy *springMoveBy = new (std::nothrow) SpringMoveBy();
springMoveBy->initWithDuration(duration, position, mass, k);
springMoveBy->autorelease();
return springMoveBy;
}
bool SpringMoveBy::initWithDuration(float duration, const Vec2& position, float mass, float k)
{
CCASSERT(mass >=0, "Number of mass must be >= 0");
if (ActionInterval::initWithDuration(duration) && mass>=0)
{
_delta = position;
_mass = mass;
_k = k;
_velocity = FIRST_VEROCITY;
_accel = FIRST_ACCEL;
_position = FIRST_POSITION;
return true;
}
return false;
}
SpringMoveBy* SpringMoveBy::clone() const
{
// no copy constructor
auto a = new (std::nothrow) SpringMoveBy();
a->initWithDuration(_duration, _delta, _mass, _k);
a->autorelease();
return a;
}
void SpringMoveBy::startWithTarget(Node *target)
{
ActionInterval::startWithTarget(target);
_previousPos = _startPosition = target->getPosition();
}
void SpringMoveBy::update(float t) // _delta = 現在座標
{
if (_target)
{
auto force = -_k * ( _position - NATURAL_LENGTH ) + _mass * GRAVITY;
_accel = force / _mass;
_velocity += _accel * t;
_velocity = _velocity * FRICTION;
_position += _velocity * t;
#ifdef CC_ENABLE_STACKABLE_ACTIONS
Vec2 currentPos = _target->getPosition();
Vec2 diff = currentPos - _previousPos;
_startPosition = diff + _startPosition;
Vec2 newPos = _startPosition;
newPos = _startPosition + Vec2(0,_position);
_target->setPosition(newPos);
_previousPos = newPos;
#else
_target->setPosition(_startPosition + Vec2(0, _position));
#endif // !CC_ENABLE_STACKABLE_ACTIONS
}
}
SpringMoveBy* SpringMoveBy::reverse() const
{
return SpringMoveBy::create(_duration, Vec2(-_delta.x, -_delta.y),
_mass, _k);
}
![]() |
| 動作例 |
![]() |
| 編集前 |
![]() |
| 編集後 |
void Effect4::onEnter()
{
EffectAdvanceBaseTest::onEnter();
//Node* gridNode = NodeGrid::create();
auto lens = Lens3D::create(10, Size(32,24), Vec2(100,180), 150);
auto move = JumpBy::create(5, Vec2(380,0), 100, 4);
auto move_back = move->reverse();
auto seq = Sequence::create( move, move_back, nullptr);
/* In cocos2d-iphone, the type of action's target is 'id', so it supports using the instance of 'Lens3D' as its target.
While in cocos2d-x, the target of action only supports Node or its subclass,
so we make an encapsulation for Lens3D to achieve that.
*/
auto director = Director::getInstance();
auto pTarget = Lens3DTarget::create(lens);
// Please make sure the target been added to its parent.
this->addChild(pTarget);
//gridNode->addChild(pTarget);
director->getActionManager()->addAction(seq, pTarget, false);
_bgNode->runAction( lens );
}
class Lens3DTarget : public Node
{
public:
virtual void setPosition(const Vec2& var)
{
_lens3D->setPosition(var);
}
virtual const Vec2& getPosition() const
{
return _lens3D->getPosition();
}
static Lens3DTarget* create(Lens3D* pAction)
{
Lens3DTarget* pRet = new (std::nothrow) Lens3DTarget();
pRet->_lens3D = pAction;
pRet->autorelease();
return pRet;
}
private:
Lens3DTarget()
: _lens3D(nullptr)
{}
Lens3D* _lens3D;
};
Lens3D::create(10, Size(32,24), Vec2(100,180), 150)
| static |
| duration | Specify the duration of the Lens3D action. It's a value in seconds. |
| gridSize | Specify the size of the grid. |
| position | Specify the center position of the lens. |
| radius | Specify the radius of the lens. |
APP_STL := gnustl_staticAPP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 -std=c++11 -fsigned-charAPP_ABI := armeabiAPP_PLATFORM := android-10ifeq ($(NDK_DEBUG),1)APP_CPPFLAGS += -DCOCOS2D_DEBUG=1APP_OPTIM := debugelseAPP_CPPFLAGS += -DNDEBUGAPP_OPTIM := releaseendif
cocos compile -p android -m debug –ndk-mode NDK_DEBUG=1
画面解像度(がめんかいぞうど、Display resolution, Screen resolution)とは、慣用的にコンピュータ等のディスプレイに表示される総画素数を指す。
端末 ピクセル デバイス ディスプレイサイズ iPhone,3G,3GS 320x480 320x480 3.5 iPhone4,4S 640x960 640x960 3.5 iPhone5,5s,5c 640x1136 640x1136 4 iPhone6,6s 750x1334 750x1334 4.7 iPhone6 Plus,6s Plus 1242x2208 1080x1920 5.5 iPad,2 768x1024 768x1024 9.7 iPad Mini 768x1024 768x1024 7.9 iPad 3,4,Air,Air2 1536x2048 1536x2048 9.7 iPad Mini 2,3,4 1536x2048 1536x2048 7.9 iPad Pro 2048x2732 2048x2732 12.9