PuzzleSDK
PongLayer类 参考

#include <TouchesTest.h>

+ 类 PongLayer 继承关系图:
+ PongLayer 的协作图:

Public 成员函数

 CREATE_FUNC (PongLayer)
 
 PongLayer ()
 
 ~PongLayer ()
 
void resetAndScoreBallForPlayer (int player)
 
void doStep (float delta)
 

Private 属性

Ball_ball
 
cocos2d::Vector< Paddle * > _paddles
 
cocos2d::Vec2 _ballStartingVelocity
 

详细描述

在文件 TouchesTest.h43 行定义.

构造及析构函数说明

◆ PongLayer()

PongLayer::PongLayer ( )

在文件 TouchesTest.cpp73 行定义.

74{
75 _ballStartingVelocity = Vec2(20.0f, -100.0f);
76
77 _ball = Ball::ballWithTexture( Director::getInstance()->getTextureCache()->addImage(s_Ball) );
78 _ball->setPosition( VisibleRect::center() );
80 addChild( _ball );
81
82 auto paddleTexture = Director::getInstance()->getTextureCache()->addImage(s_Paddle);
83
84 Vector<Paddle*> paddlesM(4);
85
86 float paddleStep =(VisibleRect::getVisibleRect().size.height - kStatusBarHeight - 30 - 3*paddleTexture->getPixelsHigh())/3 + paddleTexture->getPixelsHigh();
87 float nextPaddlePos = VisibleRect::bottom().y + 15;
88 Paddle* paddle = Paddle::createWithTexture(paddleTexture);
89 paddle->setPosition( Vec2(VisibleRect::center().x, nextPaddlePos));
90 paddlesM.pushBack( paddle );
91
92 paddle = Paddle::createWithTexture( paddleTexture );
93 paddle->setPosition( Vec2(VisibleRect::center().x, nextPaddlePos+=paddleStep) );
94 paddlesM.pushBack( paddle );
95
96 paddle = Paddle::createWithTexture( paddleTexture );
97 paddle->setPosition( Vec2(VisibleRect::center().x, nextPaddlePos+=paddleStep) );
98 paddlesM.pushBack( paddle );
99
100 paddle = Paddle::createWithTexture( paddleTexture );
101 paddle->setPosition( Vec2(VisibleRect::center().x, nextPaddlePos+=paddleStep) );
102 paddlesM.pushBack( paddle );
103
104 _paddles = paddlesM;
105
106 for (auto& paddle : _paddles)
107 {
108 addChild(paddle);
109 }
110
111 schedule( CC_SCHEDULE_SELECTOR(PongLayer::doStep) );
112}
#define kStatusBarHeight
Definition: TouchesTest.cpp:38
void setVelocity(cocos2d::Vec2 velocity)
Definition: Ball.h:47
static Ball * ballWithTexture(cocos2d::Texture2D *aTexture)
Definition: Ball.cpp:44
Definition: Paddle.h:38
static Paddle * createWithTexture(cocos2d::Texture2D *aTexture)
Definition: Paddle.cpp:43
cocos2d::Vec2 _ballStartingVelocity
Definition: TouchesTest.h:48
void doStep(float delta)
Ball * _ball
Definition: TouchesTest.h:46
cocos2d::Vector< Paddle * > _paddles
Definition: TouchesTest.h:47
static cocos2d::Rect getVisibleRect()
Definition: VisibleRect.cpp:39
static cocos2d::Vec2 center()
Definition: VisibleRect.cpp:69
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63
static const char s_Paddle[]
Definition: testResource.h:54
static const char s_Ball[]
Definition: testResource.h:53

引用了 _ball, _ballStartingVelocity, _paddles, Ball::ballWithTexture(), VisibleRect::bottom(), VisibleRect::center(), Paddle::createWithTexture(), doStep(), VisibleRect::getVisibleRect(), kStatusBarHeight, s_Ball, s_Paddle , 以及 Ball::setVelocity().

+ 函数调用图:

◆ ~PongLayer()

PongLayer::~PongLayer ( )

在文件 TouchesTest.cpp114 行定义.

115{
116}

成员函数说明

◆ CREATE_FUNC()

PongLayer::CREATE_FUNC ( PongLayer  )

◆ doStep()

void PongLayer::doStep ( float  delta)

在文件 TouchesTest.cpp127 行定义.

128{
129 _ball->move(delta);
130
131 for (auto& paddle : _paddles)
132 {
133 _ball->collideWithPaddle( paddle );
134 }
135
136 if (_ball->getPosition().y > VisibleRect::top().y - kStatusBarHeight + _ball->radius())
138 else if (_ball->getPosition().y < VisibleRect::bottom().y-_ball->radius())
140}
@ kHighPlayer
Definition: TouchesTest.cpp:34
@ kLowPlayer
Definition: TouchesTest.cpp:35
void move(float delta)
Definition: Ball.cpp:53
void collideWithPaddle(Paddle *paddle)
Definition: Ball.cpp:69
float radius()
Definition: Ball.cpp:39
void resetAndScoreBallForPlayer(int player)
static cocos2d::Vec2 top()
Definition: VisibleRect.cpp:57

引用了 _ball, _paddles, VisibleRect::bottom(), Ball::collideWithPaddle(), kHighPlayer, kLowPlayer, kStatusBarHeight, Ball::move(), Ball::radius(), resetAndScoreBallForPlayer() , 以及 VisibleRect::top().

被这些函数引用 PongLayer().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ resetAndScoreBallForPlayer()

void PongLayer::resetAndScoreBallForPlayer ( int  player)

在文件 TouchesTest.cpp118 行定义.

119{
122 _ball->setPosition( VisibleRect::center() );
123
124 // TODO -- scoring
125}

引用了 _ball, _ballStartingVelocity, VisibleRect::center() , 以及 Ball::setVelocity().

被这些函数引用 doStep().

+ 函数调用图:
+ 这是这个函数的调用关系图:

类成员变量说明

◆ _ball

Ball* PongLayer::_ball
private

在文件 TouchesTest.h46 行定义.

被这些函数引用 doStep(), PongLayer() , 以及 resetAndScoreBallForPlayer().

◆ _ballStartingVelocity

cocos2d::Vec2 PongLayer::_ballStartingVelocity
private

在文件 TouchesTest.h48 行定义.

被这些函数引用 PongLayer() , 以及 resetAndScoreBallForPlayer().

◆ _paddles

cocos2d::Vector<Paddle*> PongLayer::_paddles
private

在文件 TouchesTest.h47 行定义.

被这些函数引用 doStep() , 以及 PongLayer().


该类的文档由以下文件生成: