一、创建文件·

FishAchor.h还有FishAchor.cpp。

主要就是创建每种鱼的类,方便以后的取用~,很多是重复性的操作,然后我们是mini版,暂时也就加入大概6钟鱼就好= =,然后我们现在就来搭建~。

二、鱼的基类

1、定义~

class FishActor : public Sprite  //继承精灵类,然后作为各种鱼的基类,有最基本的属性
{
public:enum class FishActorType //首先在这里需要得知,鱼的类型 {SmallFish,AngelFish,Croaker,Amphiprion,Bream,MarlinsFish,};/** Speed property of the fishes */CC_SYNTHESIZE(float, speedX, SpeedX);     //速度~CC_SYNTHESIZE(float, speedY, SpeedY);FishActorType fishType;       //鱼的类型/** Create the fish by their types */static FishActor* createWithType(FishActorType fishType); //创建方法~/** Play the death animation */virutal Animate* playDeathAnimation();      //鱼死亡时的动画~/** Update the fish movement */void updateFishMovement(float dt);     //鱼出现的动画~/** Activate the fish movement */virutal void activateFishMovement();         //激活protected:CC_SYNTHESIZE(float, fishScore, FishScore);     //鱼的得分~};

这个主要是作为一个大的接口类,方便用同一个接口,创建不同的鱼,节约重复性的代码操作~。具体的实现呢~

2、实现~

(1)创建方法~

FishActor* FishActor::createWithType(FishActorType fishType)
{FishActor *fish=nullptr;             //创建一个空指针//Create the fishes by the fish typeswitch (fishType)              //根据类型进行创建{case FishActorType::SmallFish:fish = SmallFishActor::create();break;case FishActorType::AngelFish:fish = AngelFishActor::create();break;case FishActorType::Croaker:fish = CroakerActor::create();break;case FishActorType::Amphiprion:fish = AmphiprionActor::create();break;case FishActorType::Bream:fish = BreamActor::create();break;case FishActorType::MarlinsFish:fish = MarlinsFishActor::create();break;default:break;}return fish;
}

(2)鱼移动的movement

void FishActor::updateFishMovement(float delta)
{auto direction = rand() % 3 - 1.0f;auto shiftX = (rand() % 5 + 1)*direction;auto shiftY = (rand() % 5 + 1)*direction;setSpeedX(shiftX == 0 ? 1 : shiftX);setSpeedY(shiftY == 0 ? 1 : shiftY);auto rotation = -atan2(shiftY, shiftX);this->setRotation(rotation*180.0f / 3.14f + 180.0f);
}

3、其中一种鱼的创建~

(1)类的声明~

class AngelFishActor : public FishActor
{public:bool init();CREATE_FUNC(AngelFishActor);Animate* playDeathAnimation();      //每个鱼敲掉的动画不一样~void activateFishMovement();
};

(2)具体实现

1、init()

bool SmallFishActor::init()
{FishActor::init();    //一般不会不成功的= =,是继承Sprite里面的创建~setSpeedX(1.0f);     //设置速度~setSpeedY(1.0f);setFishScore(1.0f);      设置得分~fishType = FishActorType::SmallFish;//Read the swimming animations texturesauto fishes = Vector<SpriteFrame*>();//动态数组容器fishes.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_actor_001.png"));fishes.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_actor_002.png"));fishes.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_actor_003.png"));fishes.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_actor_004.png"));//Create swimming animationauto fishAnimation = Animation::createWithSpriteFrames(fishes, 0.1);auto fishAnimate = Animate::create(fishAnimation);//Run the swiming action forever
    runAction(RepeatForever::create(fishAnimate));return true;
}

2、鱼移动的动画创建

void SmallFishActor::activateFishMovement()
{schedule(schedule_selector(FishActor::updateFishMovement), 3 + rand() % 2); //调用基类函数~
}

3、死掉的动画~

Animate* SmallFishActor::playDeathAnimation()
{//Read the death anmtions texturesauto deathFrames = Vector<SpriteFrame*>();  //创建一个数组deathFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_death_001.png"));deathFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_death_002.png"));deathFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_death_003.png"));deathFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_death_004.png"));deathFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("SmallFish_death_005.png"));//Create the death anmationauto deathAnimation = Animation::createWithSpriteFrames(deathFrames, 0.1);//设置播放的时间间隔~auto deathAnimate = Animate::create(deathAnimation);   返回创建好的动画~
return deathAnimate;
}

三、七说八说~

图片资源已经上传的github~:https://github.com/Wenne/FishingMini

cocos2dx游戏开发——捕鱼达人mini版学习笔记(一)——FishAchor的搭建相关推荐

  1. cocos2dx 字体外发光_《Cocos2d-x游戏开发实战精解》学习笔记2--在Cocos2d-x中显示一行文字...

    在Cocos2d-x中要显示文字就需要用到Label控件.在3.x版本的Cocos2d中,舍弃了之前版本所使用的LabelTTF.LabelAtlas.LabelBMFont 3个用于显示文字的类,而 ...

  2. cocos2dx掼蛋_cocos2dx游戏开发——别踩白块学习笔记(一)——Block类

    一.Block类介绍 当然啦,Block类在这个游戏里就是必需品= =,因为整体都是由这个搞出来的,所以我们可以把游戏需要实现的功能都放在这里. 主要有下面这些功能(经典模式): 1.创建一个Bloc ...

  3. Windows游戏编程大师技巧第二版学习笔记之第一章 实验补充

    前面记录的一下看书中的重点,编程还是要动手,下面就来动手试试,这里选择VC6.0编译器 这里先来配置游戏编程环境,原书中的dx81sdk_full.exe一共是1百多MB,其实没必要整那么多,看我在我 ...

  4. [C++]DirectX 12 3D游戏开发实战—第9章 学习笔记02 2019.5.3

    仅个人学习用,请勿转载 词汇 漫反射反照率纹理图:diffuse albedo texture map 过滤器:fliter 纹理放大:magnification 常数插值:constant inte ...

  5. Cocos2dx游戏开发素材/学习网站分享

    本节将分享学习Cocos2dx游戏开发中素材/学习网站. 目录 一. 学习网站 1. 学习手册 2. API大全 二. 素材网站 1. 图片素材 爱给网 Awesome wallpapers 懒人图库 ...

  6. DirectX 9.0c游戏开发手记之“龙书”第二版学习笔记之1: 开场白

    在开场白之前的说明: 这是"DirectX 9.0c游戏开发手记"的第一部分,叫做"'龙书'第二版学习笔记",讲的是我做"龙书"第二版(原名 ...

  7. cocos2dx掼蛋_精通Cocos2d-x游戏开发(进阶卷) (王永宝著) 完整pdf扫描版[98MB]

    <精通Cocos2d-x游戏开发>分为<基础卷>和<进阶卷>两册.这两册都有明确的写作目的.<基础卷>专注于Cocos2d-x引擎基础,致力于让Coco ...

  8. cocos2d-x游戏开发基础与实战 经典视频教程

    cocos2d-x游戏开发基础与实战 经典视频教程 cocos2d-x游戏开发工资高吗? 精通C/C++,熟练掌握Cocos2d-x引擎及其Cocos2d-x引擎周边开发工具,了解游戏开发常用的工具和 ...

  9. Java小游戏之捕鱼达人000.序章

    000 序言 0.1 吐槽 大四专业校内实习,然后没有期待中的C/C++的项目实习(是意料之中的Java 老师要求做一个Java小游戏 我就蒙了,脑海中闪现过很多念头 不是把不是把,没花钱去培训机构学 ...

最新文章

  1. 为什么要进行数据归一化
  2. CAXA电子图板2020中文版
  3. java回文数算法for_【Java】【每日算法/刷穿 LeetCode】9. 回文数(简单)
  4. 【Lucene4.8教程之五】Luke
  5. Framework Design Studio 发布了
  6. E95-DTU(4G01-485)数传电台的特点及其应用详解
  7. PotPlayer安装与配置
  8. HTTP的长连接和短连接通俗解释以及应用场景
  9. 删除数组对象 相同的值 制定数组对象
  10. Atitti 数据库事务处理 attilax总结
  11. Intel CPU性能linpack测试
  12. 业务层战略制定的思路和方法_如何确保公司年度战略目标落地—打造战略执行的方法论...
  13. 设计模式入门--发布订阅模式
  14. iOS Block弱引用
  15. 三层交换机内网访问外网
  16. Ubuntu安装ESPNET(搞了一个多月)
  17. 根号分治练手题 西比拉先知系统 题解
  18. Python 文件 tell() 方法
  19. MongoDB中索引的创建和使用详解
  20. matlab怎么对语音信号取样,语音信号采样和频谱分析

热门文章

  1. 字节跳动面试:java编程思想电子版非pdf
  2. 正则表达式电话和姓名加星
  3. mysql 中float存入int数据显示失真问题
  4. 华科大计算机跨考,华中科大计算机概况_跨考网
  5. spark kafka java api_java实现spark streaming与kafka集成进行流式计算
  6. 运算放大器基本公式_跨阻放大器稳定性
  7. Python升级pip并安装opencv、moviepy包
  8. 怎么把php写入文件格式,如何将一个PHP数组有格式的写入文件中
  9. 计算机程序C语言若初始数为48,2016年计算机软考程序员模拟选择试题
  10. 20200221:在排序数组中查找元素的第一个和最后一个位置(leetcode34)