Code Monkey home page Code Monkey logo

cocos-tutorial-first-game's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cocos-tutorial-first-game's Issues

polished_project_ts在creator 2.1.0下运行拾取不到星星的bug

因为Player.ts下的getCenterPos返回的是只有x和y的cc.v2

getCenterPos () {
    //var centerPos = cc.v2(this.node.x, this.node.y + this.node.height/2);
    //必须改成下面带有z坐标的v3,上面注释掉的v2不行
    var centerPos = cc.v3(this.node.x, this.node.y + this.node.height/2, 0);
    return centerPos;
}

从而导致如下Star.ts里getPlayerDistance 计算距离dist的结果为NaN了

getPlayerDistance () {
    // 根据 player 节点位置判断距离
    var playerPos = this.game.player.getCenterPos();
    // 根据两点位置计算两点之间距离
    var dist = this.node.position.sub(playerPos).mag();
    return dist;
 }

debug看了下是因为cc.Node的getPosition返回的是Vec3而不是Vec2,所以this.node.position.sub(playerPos).mag()结果就是NaN了

无法用新版的tween实现

版本2.3.3

新版CCC在运行时提示Action即将被废弃,推荐使用tween来做缓动动画,于是用tween重写了缓动部分 (TypeScript代码):

cc.tween(this.node)
        .repeatForever(
            cc.tween(this.node)
                .by(this.jumpDuration, { position: cc.v2(0, this.jumpHeight) }, { easing: 'cubicOut' })
                .by(this.jumpDuration, { position: cc.v2(0, -this.jumpHeight) }, { easing: 'cubicIn' })
                .call(() => this.playJumpSound())
        )
        .start();

但是在运行时发现update()函数里更新node.x的代码不能正常工作:

update(dt: number) {
    // ...
    // 上面是计算 this.xSpeed 的代码
    this.node.x += this.xSpeed * dt;
}

打印this.node.x发现 x 的值没有正常累加,感觉是 tween 的位移计算重置了 this.node.x 的值?打印出来的值大概是这样( x1 = 本帧修改前的this.node.x,v = xSpeed * dt,x2 = x1 + v ):

...
x1: 0,  v: 6.667600000000676,  x2: 6.667600000000676
x1: 0,  v: 6.653600000000005,  x2: 6.653600000000005
x1: 0,  v: 6.687199999999575,  x2: 6.687199999999575
...

请问为什么会这样?用tween的时候如何正确更新node的位置?

Keyboard keys A and D not responding to code...I did click on Game Canvas as suggested

Hi Everyone,
The following code is not working
// Initialize the keyboard input listening
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this); ..
when I run it on Simulator I get an error on that ...


Simulator: E/jswrapper (268): ERROR: Uncaught TypeError: Cannot read property 'a' of undefined, location: assets/scripts/Player.js:0:0
Simulator: jsb: ERROR: File ..\manual\jsb_cocos2dx_manual.cpp: Line: 653, Function: invokeJSKeyboardCallback
Simulator: invokeJSKeyboardCallback call function failed!


I have no clue on how to fix this ...any advice will be greatly appreciated.
thank you!

cc.eventManager is not working

my cocos crater version is 1.9.3

and message shows eventManager will be removed. but when i try EventTarget i get an error again. can you update tutorial accordingly.

CCDebugger.js:343 The 'cc.eventManager' will be removed in v2.0, please use 'cc.EventTarget or cc.systemEvent' instead.

section [编写跳跃和移动代码] 错误

原文:
`setJumpAction: function () {
// 跳跃上升
var jumpUp = cc.moveBy(this.jumpDuration, cc.p(0, this.jumpHeight)).easing(cc.easeCubicActionOut());
// 下落

    var jumpDown = cc.moveBy(this.jumpDuration, cc.p(0, -this.jumpHeight)).easing(cc.easeCubicActionIn());
    // 不断重复

    return cc.repeatForever(cc.sequence(jumpUp, jumpDown));
},

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Player.js
onLoad: function () {
// 初始化跳跃动作
this.jumpAction = this.setJumpAction();
this.node.runAction(this.jumpAction);
},
`
我的环境:Win10 Pro 64bit ,中文,VS2017 ,Cocos Creator 1.5

错误:经实践只能用.easing(cc.easyIn()/或cc.easyInOut()之类/),直接用tutorial的easeCubicActionOut()会Invalid key
疑问: 文章前面并只有setJumpAction,onLoad里却冒出了this.jumpAction ,不知道目的是什么??

随机生成星星遇到bug

Uncaught TypeError: Cannot read property 'jumpHeight' of null

这是游戏运行报的错误,this.player.getComponent('Player').jumpHeight 这个获取不到这个属性
但是我输出this.player 可以得到这个组件

开发工具为最新版本

//
游戏开始时得分从0开始,每收集一个星星分数就会加1。要显示得分,首先要创建一个 Label 节点。在层级管理器中选中Canvas节点,右键点击并选择菜单中的创建新节点->创建渲染节点->Label(文字),一个新的 Label 节点会被创建在Canvas下面,而且顺序在最下面。接下来我们要用如下的步骤配置这个 Label 节点:

将该节点名字改为score
将score节点的位置(position属性)设为(0, 180)。
选中该节点,编辑Label组件的string属性,填入Score: 0的文字。
将Label组件的Font Size属性设为50。
从资源管理器中拖拽assets/mikado_outline_shadow位图字体资源(注意图标是bmfont)到Label组件的Font属性中,将文字的字体替换成我们项目资源中的位图字体。

//

完全按照上述步骤, 在资源管理器里面拖动"mikado_outline_shadow" BF 资源到Canvas下的label里的Font属性时候,提示 TypeError: Cannot read property '_fntConfig' of undefined

之后字体没有在预览里显示出来,运行之后显示也不正常.

程序设计存在问题.

//
现在要添加主角收集星星的行为逻辑了,这里的重点在于,星星要随时可以获得主角节点的位置,才能判断他们之间的距离是否小于可收集距离,如何获得主角节点的引用呢?别忘了我们前面做过的两件事:

  1. Game组件中有个名叫player的属性,保存了主角节点的引用。
  2. 每个星星都是在Game脚本中动态生成的。
    所以我们只要在Game脚本生成Star节点实例时,将Game组件的实例传入星星并保存起来就好了,之后我们可以随时通过game.player来访问到主角节点。
    //

这句话,原本Star就被Game引用了,现在又把Game赋值给Star.这种设计思路不太好会不会?循环引用容易出现内存泄漏问题.最好就是把player直接赋值给Star,因为player和Star是并行关系.

按照我的思路,拾取到星星后的处理应该定义在Game里面,由Game去生成新的星星,摧毁老的星星,增加积分.这个功能可以在Star类里声明一个回调函数,在Game里面设置回调函数的具体工作.

//Game.js
spawnNewStar: function() {
// 使用给定的模板在场景中生成一个新节点
var newStar = cc.instantiate(this.starPrefab);
var star = newStar.getComponent('Star');
var self = this;
star.player = this.player;
star.pickedCallBackFunc = (star) => {
star.node.destroy();
self.spawnNewStar();
self.gainScore();
};

    // 重置计时器,根据消失时间范围随机取一个值
    star.duration = this.starDuration = this.minStarDuration + cc.random0To1() * (this.maxStarDuration - this.minStarDuration);
    this.timer = 0;
    
    // 将新增的节点添加到 Canvas 节点下面
    this.node.addChild(newStar);
    // 为星星设置一个随机位置
    newStar.setPosition(this.getNewStarPosition());
},

实例代码问题

Hi,朋友
setInputControl: function () { var self = this; // 添加键盘事件监听 cc.eventManager.addListener({ event: cc.EventListener.KEYBOARD, // 有按键按下时,判断是否是我们指定的方向控制键,并设置向对应方向加速 onKeyPressed: function(keyCode, event) { switch(keyCode) { case cc.KEY.a: self.accLeft = true; self.accRight = false; break; case cc.KEY.d: self.accLeft = false; self.accRight = true; break; } }, // 松开按键时,停止向该方向的加速 onKeyReleased: function(keyCode, event) { switch(keyCode) { case cc.KEY.a: self.accLeft = false; break; case cc.KEY.d: self.accRight = false; break; } } }, self.node); },
上个方法中为什么要在开头保存self,我试过不保存直接用this却得不到想要的结果,没有理解为什么?

教程游戏运行时出现错误,请问如何调试。

我按照教程上所写一步步做到最后总结。运行后发现在游戏失败重置后Player第一次落地时整个游戏会卡住。

请问,我猜想是callback调用的问题,但是我不知道如何调试,有何方法调试呢?(同时在写教程代码的同时因为不少的拼写错误导致游戏运行出错也不知道如何调试)

为什么complete_project项目把代码修改成ES6无法运行

如题,配置和publish_project_es6的配置一模一样的,为什么就运行不了,提示错误: Can not declare Star.onLoad, it is already defined in the prototype of StarPlease specifiy a default value for "onLoad" property at its declaration: 😂

Player did not call update

i tried to recreate from zero the polished project, but some how when i call this.player.startMoveAt function, it did not call the Player:update function. so Player cannot move when i tap on left/right key. anyone has the same issue?

2.1版本在星星上暂存Game对象引用出错

newStar.getComponent('Star').game=this;
不注释出现错误,注释无法实现功能
报错:(271)ERROR: Uncaught TypeError: Cannot read property 'length' of null, location: src/cocos2d-jsb.js:0:0
Simulator: E/jswrapper (534): [ERROR] (..\cocos\scripting\js-bindings\jswrapper\v8\Object.cpp, 534): Invoking function (1012C818) failed!

The main sense is nothing but dark

No error is reported, but the screen is dark, I can hear the audio and feels like I could control it, but I can not see anything.

Creator version: 2.1.2 WIN
Code version: V2.0 polished

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.