30/09/2018, 22:40
Nhờ anh chị nhận xét giúp em đoạn code này, em viết code cho cocos2d-x với ngôn ngữ c++, em cảm ơn ạ
File Game.cpp:
#include Game.h
#include Result.h
USING_NS_CC;
Scence” Game::createScene(){
auto scene = Scene::create();
auto layer = Game::create();
scene->addChild(layer);
}
Int score = 0;
Bool Game::init(){
auto traiBong = Sprite(“traibong.jpg”);
traiBong-> setAnchorPoint(Vec2(0,0));
traiBong-> setPosition(Vec2(visiblePosition.weight/2, visiblePosition.height/2));
addChild(traiBong);
auto khungThanh = Sprite(“khungThanh.jpg”);
Vec2 viTri = visiblePosition.weight/2;
khungThanh->setAnchorPoint(Vec2(0.5,0));
khungThanh->setPosition(Vec2(viTri,0);
addChild(khungThanh);
auto touchListener = EventLinsterTouchOneByOne::create();
touchListener-> onTouchBegan = CC_CALLBACK_2(onTouchBegan,this);
touchListener-> onTouchEnded= CC_CALLBACK_2(onTouchEnded,this);
this->getEnvenDispatchar()->addEventListenerWithSenceGraphFriority
(touchListener,this);
bool onTouchBegan(Touch* touch, Event* event){
Vec2 touchLocation = touch->getPosition();
auto actionMove = MoveTo:: create(0.2, touchLocation);
traiBong->runAction(actionMove);
if(traiBong->getPosition().weight < viTri + 20){
if(traiBong->getPosition().weight > viTri - 20){
if(0 <= traiBong->getPosition().height <= 5){
score++;
}
}
}
return true;
}
void onTouchEnded(Touch* touch, Event* event){
traiBong->setPosition(Vec2(viTri, visiblePosition.height/2));
}
auto nextPage = Sprite::creat(“nextPage.png”);
nextPage -> setAnchorPoint(Vec2(0,0));
nextPage -> setPosition(Vec2(0,0));
addChild(nextPage);
auto touchListener2 = EventListenerTouchOneByOne::create();
touchListener2 -> onTouchBegan = CC_CALLBACK_2
(onTouchBegan2,nextPage);
nextPage->getEventDispatchar()->addEventListenerWithSceneGraphFriority
(touchListener2,nextPage);
bool onTouchBegan2(Touch* touch, Event* event){
auto chuyenTrang = Result::create(score);
Director:getInstance()->ReplaceScene(chuyenTrang);
Return true;
}
Return true;
}
File Result.cpp:
#include Game.h
#include Result.h
USING_NS_CC;
int diemSo;
Scence” Result::createScene(int soDiem){
diemSo = soDiem;
auto scene = Scene::create();
auto layer = Game::create();
scene->addChild(layer);
}
bool Reuslt::init(){
auto bongNho = Sprite::create(“bongnho.cpp”);
bongNho->setAnchorPoint(0,0);
int hoanhdo = 0;
for(int i = 0; i < diemSo, i++){
bongNho->setPosition(Vec2(hoanhdo,0));
addChild(bongNho);
hoanhdo+= 10;
}
Return true;
}
Bài liên quan
This post was flagged by the community and is temporarily hidden.