Home Database Mysql Tutorial cocos2dx 3.0 飞机大战

cocos2dx 3.0 飞机大战

Jun 07, 2016 pm 03:42 PM
course airplane

由于课程需要,然后又水平有限,所以写了个飞机大战,加上不会画画,所以图片资源也是从微信apk解压出来的,设计思路参考的偶尔e网事。 闲话不说,先讲一下设计,大体上一共分为3个场景,场景下面是Layer 开始场景:WelcomeScene --WelcomeLayer 类欢迎界面

由于课程需要,然后又水平有限,所以写了个飞机大战,加上不会画画,所以图片资源也是从微信apk解压出来的,设计思路参考的偶尔e网事。


闲话不说,先讲一下设计,大体上一共分为3个场景,场景下面是Layer


开始场景:WelcomeScene -->WelcomeLayer  类似欢迎界面

游戏主场景:GameScene  --> GameLayer  游戏元素添加 和 碰撞检测

结束场景:GameOverScene -->GameOverLayer


然后是游戏的元素,在GameLayer添加,一个分为4个Layer:


PlaneLayer:主角层 

EnemyLayer:敌机层 ,分为3种,每种敌机生命值不一样

UFOLayer: 道具层,bullet和加bomb

BulletLayer:子弹层 bullet 和mutiBullet


然后简单讲一下碰撞检测的实现:

if(bullet->boundingBox().intersectsRect(enemy1->getBoundingBox())){
				if(enemy1->getLife() == 1){
					enemy1->loseLife();
					bulletsToDelete->addObject(bullet);
					enemy1ToDelete->addObject(enemy1);
					score += ENEMY1_SCORE;
					this->mControlLayer->updateScore(score);
				}
			}
Copy after login
Rect Enemy::getBoundingBox(){
	Rect rect = this->m_sprite->boundingBox();
	Point pos = this->convertToWorldSpace(rect.origin);
	return Rect(pos.x, pos.y, rect.size.width, rect.size.height);
}
Copy after login


还有再来就是子弹层的处理:

子弹发射需要步骤:1.添加子弹,2.移动子弹,3移除子弹

由于需要源源不断的发射子弹,所以将子弹添加到一个SpriteBatchNode节点中,然后在这个SpriteBatchNode节点对子弹进行添加,移动,和移除,这样子做的好处是只需要渲染一次,降低内存消耗

auto texture = TextureCache::getInstance()->textureForKey("shoot.png");
	bulletBatchNode = SpriteBatchNode::createWithTexture(texture);
	this->addChild(bulletBatchNode);
Copy after login


然后再讲一下图片资源的处理:


下载这个工具:plist解析工具

将微信需要的资源解析出来,然后可以用photoshop处理一下,哈哈,可以将微信的图片去掉,随便p上自己的名字

然后用TexturePacker打包,恩,大概就像这样子


cocos2dx 3.0 飞机大战


最后再讲一下编译成android工程的步骤和细节:


1.先在Android.mk文件中添加所有必须的cpp

2.记得在AppDelegate cpp 中添加分辨率适应

glview->setDesignResolutionSize(480,800,ResolutionPolicy::SHOW_ALL);
Copy after login
3.在proj.android文件夹下面修改AndroidManifest.xml 竖屏属性:
android:screenOrientation="portrait"
Copy after login

4.cmd到工程目录,命令:cocos compile -p android -j 4




源码:飞机大战



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Airlines adjust rules for ticket refunds and changes, Air China provides domestic no-reason refund coupons x 2 Airlines adjust rules for ticket refunds and changes, Air China provides domestic no-reason refund coupons x 2 Jan 08, 2024 pm 06:26 PM

According to news from this site on January 6, China Southern Airlines and China Eastern Airlines have successively issued announcements on adjustments to their ticket cancellation and change rules, including factors such as aircraft model changes that lead to inability to travel, flight changes that lead to route changes, and flight stopover delays, etc., into the application for free ticket refunds and changes. scope, and at the same time relax the rules for cancellation due to illness, which will take effect from 0:00 on January 10, 2024, Beijing time. China Southern Airlines has made the following adjustments: Expanding the scope of free ticket refunds and changes to include factors such as changes in aircraft types that prevent you from making the trip, flight stoppage delays, airport transfers, force majeure and other factors. Relaxation of Cancellation and Refund Rules Due to Sickness 1. Passengers who are unable to travel due to illness can apply for changes or refunds due to illness for domestic and international tickets held by China Southern Airlines. 2. The proof of cancellation due to illness is adjusted to payment invoice or hospitalization deposit certificate (choose one of the two)

Juneyao Airlines' 'Genshin Impact” has officially started sailing. During the first flight week, enjoy the special experience of commemorating boarding passes, lunch boxes and water bottles. Juneyao Airlines' 'Genshin Impact” has officially started sailing. During the first flight week, enjoy the special experience of commemorating boarding passes, lunch boxes and water bottles. Nov 11, 2023 pm 06:37 PM

On November 11, Juneyao Airlines announced that “Genshin Impact” had successfully made its maiden flight, and also launched Juneyao Airlines × Genshin Impact-themed peripheral products. These peripheral products include a 787 aircraft model made at a scale of 1:150, a "Genshin Impact" third-anniversary cooperation passport bag, and a third-anniversary cooperation flight blanket. Our website noted that the "Genshin Impact" will fly in 2023. From November 8 to November 8, 2024, the aircraft type is Boeing 787-9 wide-body aircraft, with 29 business class seats and 295 economy class seats. How to purchase tickets: Open the Juneyao Airlines App and click on the top picture of "Genshin Impact 3rd Anniversary" on the homepage. Go to the "Genshin Impact 3rd Anniversary Themed Flight" landing page to view the planned "Genshin Impact" flights. Select the departure time and click "Book" Enter the ticket purchase page for the first flight

Southwest Airlines is expected to obtain certification for the Boeing 737 MAX 7 aircraft in April next year and plans to put it into operation in October-November. Southwest Airlines is expected to obtain certification for the Boeing 737 MAX 7 aircraft in April next year and plans to put it into operation in October-November. Nov 11, 2023 am 09:37 AM

According to news from this website on November 11, according to Reuters, a Southwest Airlines executive revealed that the Boeing 737 MAX7 aircraft will be certified by the US Federal Aviation Administration in April 2024 and will begin operations from October to November. This site noticed that Southwest Airlines announced new orders for an additional 108 MAX7 aircraft last month, which are expected to be delivered before 2031. However, the aircraft's delivery schedule depends on certification by the US Federal Aviation Administration (FAA), and delays in certification have forced it to convert dozens of MAX7 orders to MAX8. On Thursday night, Southwest Airlines Chief Operating Officer Andrew Watterson said in an interview: "Our internal planning is that we expect it to be in 4

AG100 'Lingyan', a junior civilian training aircraft independently developed in China, was officially launched and delivered. The equipment is equipped with automatic driving technology. AG100 'Lingyan', a junior civilian training aircraft independently developed in China, was officially launched and delivered. The equipment is equipped with automatic driving technology. Jan 23, 2024 am 08:33 AM

This website reported on January 21 that Aviation Industry General Aviation held a delivery ceremony for the first batch of new-generation domestic junior trainer aircraft "Lingyan" AG100. The first batch was delivered to Henan New Silk Road Aviation School and Zhuhai AVIC Flight School. This website noticed that the "Lingyan" AG100 aircraft is a new generation of domestically produced civilian primary trainer aircraft independently developed by Aviation Industry General Aviation. It has introduced a third-seat auxiliary training function to improve the efficiency of flight training; it is equipped with an automatic driving system and a parachute landing system. system to ensure the safety of the crew and passengers to the greatest extent; it adopts high-reliability design, and the entire aircraft adopts low-cost composite material design and manufacturing technology. At the same time, the AG100 is equipped with the latest ROTAX915is engine, which can use automotive gasoline to facilitate fuel security and reduce training costs.

Boeing: The world will need nearly 44,000 new commercial aircraft in the next 20 years Boeing: The world will need nearly 44,000 new commercial aircraft in the next 20 years Jul 23, 2024 pm 06:55 PM

This website reported on July 22 that on the eve of the Farnborough Air Show, Boeing released the 2024 Civil Aviation Market Outlook (CMO), predicting that global airlines will need nearly 44,000 new civil aircraft by 2043. With air travel fully restored, the latest aircraft deliveries over the next 20 years are up 3% from last year's forecast. The outlook also predicts that emerging market and global single-aisle market demand will continue to be the main growth driver for the civil aviation industry. According to the CMO, air passenger traffic will grow at an average annual rate of 4.7% over the next 20 years compared with 2023. Highlights of the CMO forecast for the next 20 years include: The global civil fleet is expected to grow by 3.2% per year, a slower growth rate than air traffic as airlines continue to increase load factors and increase the number of aircraft per day.

Honda Aircraft Company announces name of light business jet HondaJet Echelon: single-pilot, can seat 10 people Honda Aircraft Company announces name of light business jet HondaJet Echelon: single-pilot, can seat 10 people Oct 19, 2023 am 09:25 AM

According to news from this site on October 18, Honda's aircraft business subsidiary, Honda Aircraft Company (hereinafter referred to as: HACI), held a press conference at the media day of the 2023 American Business Aviation Conference and Exhibition, officially announcing the name of the new light business jet. "HondaJetEchelon". According to reports, "Echelon" refers to a trapezoidally arranged flight queue. This flight queue has high aerodynamic efficiency and can save energy consumption. At the same time, "Echelon" also has a derived meaning of "selected categories". The name embodies HACI’s vision for the future of business jets: efficiency first, comfort always. According to inquiries on this site, HondaJet Echelon (

Airbus' first full life cycle aircraft service center launched in Chengdu, Sichuan, China Airbus' first full life cycle aircraft service center launched in Chengdu, Sichuan, China Jan 24, 2024 pm 11:33 PM

Airbus Aircraft Full Life Cycle Service Center announced today that it is put into operation and will provide solutions for aircraft full life cycle management. The center is located in Chengdu, Sichuan, China. According to reports, as its first one-stop service center, the Airbus aircraft full life cycle service center will be oriented to various aircraft models, covering business scope from aircraft parking and storage to maintenance, upgrades, modifications, dismantling, recycling and disassembly. Dissolved second-hand aviation supplies distribution business. The service center has obtained relevant certifications from the European Aviation Safety Agency (EASA) and the Civil Aviation Administration of China. It is planned to cover a total area of ​​717,000 square meters in the future and is planned to build and park 125 aircraft. From operation to 2025, the center will gradually expand operations and directly employ 150 employees. Airbus aircraft full life cycle services

How to use C++ to implement a simple airplane booking system? How to use C++ to implement a simple airplane booking system? Nov 02, 2023 pm 12:35 PM

How to use C++ to implement a simple airplane booking system? As air traffic develops and people's demand for comfortable travel increases, aircraft booking systems have become increasingly important. In this article, we will learn how to implement a simple airplane booking system using the C++ programming language. This system will allow users to check flight information, select seats, book and cancel tickets and other functions. First, we need to create a Flight class to represent flights. This class should include the following attributes: flight number, departure place, destination, departure time

See all articles