http://www.drjiro.com/game-engine/cocos ... tutorial5/
こちらを参考にしてコードを作成したのですがランナー側のsetDebugDrawMaskが表示されません
そして,ランナーはなぜか床に半分めり込みます(当たり判定が真ん中?).
一部ソースを変えてはいますが影響はないはずなのですが原因を教えていただけませんでしょうか?
//PlayScene.cpp
#include "PlayScene.h"
#include "GameplayLayer.h"
#include "BackgroundLayer.h"
#include "StatusLayer.h"
USING_NS_CC;
Scene* PlayScene::createScene()
{
auto scene = Scene::createWithPhysics();
auto world = scene -> getPhysicsWorld();
world -> setGravity(Vec2(0,-900));
world -> setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
auto layer = PlayScene::create();
scene -> addChild(layer);
return scene;
}
bool PlayScene::init()
{
if(!Layer::init())
{
return false;
}
initPhysics();
auto backgroundLayer = BackgroundLayer::create();
addChild(backgroundLayer);
auto gameplayerLayer = GameplayLayer::create();
addChild(gameplayerLayer);
auto statusLayer = StatusLayer::create();
addChild(statusLayer);
return true;
}
bool PlayScene::initPhysics()
{
auto wallBottom = Node::create();
addChild(wallBottom);
wallBottom -> setAnchorPoint(Vec2(0,1));
wallBottom -> setPosition(Vec2(0,500));
wallBottom -> setContentSize(Size(3000,100));
std::string str = StringUtils::format("%lf--%lf",wallBottom->getContentSize().width,wallBottom->getContentSize().height);
auto material = PHYSICSBODY_MATERIAL_DEFAULT;
material.density = 1.0f;
material.restitution = 0.0f;
material.friction = 0.0f;
auto body = PhysicsBody::createBox(wallBottom->getContentSize(), material);
body->setDynamic(false);
body->setContactTestBitmask(true);
wallBottom->setPhysicsBody(body);
return true;
}
//PlayScene.h
#ifndef __MyGame03__PlayScene__
#define __MyGame03__PlayScene__
#include <stdio.h>
#include "cocos2d.h"
class PlayScene : public cocos2d::Layer
{
private:
public:
static cocos2d::Scene* createScene();
virtual bool initPhysics();
virtual bool init();
CREATE_FUNC(PlayScene);
};
#endif /* defined(__MyGame03__PlayScene__) */
//GameplayLayer.cpp
#include "GameplayLayer.h"
USING_NS_CC;
bool GameplayLayer::init()
{
if(!Layer::init())
{
return false;
}
auto visibleSize = Director::getInstance() -> getVisibleSize();
Vec2 origin = Director::getInstance() -> getVisibleOrigin();
//auto w_ratio = visibleSize.width/640;
auto h_ratio = visibleSize.height/960;
auto cacher = SpriteFrameCache::getInstance();
cacher -> addSpriteFramesWithFile("sprites.plist");
Vector<SpriteFrame*> frames(3);
char str[100] = {0};
for (int i = 0; i < 2 ; i++){
sprintf(str,"player%d.png",i+1);
auto a_frames = SpriteFrameCache::getInstance()->getSpriteFrameByName(str);
frames.pushBack(a_frames);
}
auto animation = Animation::createWithSpriteFrames(frames,0.1f);
auto animate = Animate::create(animation);
auto repeat = RepeatForever::create(animate);
auto spritePlayer = Sprite::create();
auto player_Size = spritePlayer -> getContentSize();
spritePlayer -> runAction(repeat);
//spritePlayer -> setAnchorPoint(Vec2(0.5,0));
spritePlayer -> setPosition(origin.x,origin.y+480*h_ratio);
auto material = PHYSICSBODY_MATERIAL_DEFAULT;
material.density = 1.0f;
material.restitution = 0.0f;
material.friction = 0.0f;
auto body = PhysicsBody::createBox(player_Size,material);
body -> setMass(1.0f);
body -> setRotationEnable(false);
body -> setGravityEnable(true);
body -> setContactTestBitmask(true);
body -> setDynamic(true);
body -> applyImpulse(Vect(50.0f,50.0f),Point(0,0));
spritePlayer -> setPhysicsBody(body);
addChild(spritePlayer);
return true;
}
//GameplayLayer.h
#ifndef __MyGame03__GameplayLayer__
#define __MyGame03__GameplayLayer__
#include <stdio.h>
#include "cocos2d.h"
class GameplayLayer : public cocos2d::Layer
{
private:
public:
static cocos2d::Scene* createScene();
virtual bool init();
CREATE_FUNC(GameplayLayer);
};
#endif /* defined(__MyGame03__gameplayLayer__) */