Quantcast
Channel: Cocos Forums - Latest topics
Viewing all 17056 articles
Browse latest View live

Does HTML games still support CANVAS? (CocosCreator 2.4.2)

$
0
0

Hi all,

In previous versions, I know CANVAS & WEBGL were supported to run HTML games. Since I couldn’t figure it out myself, I would like to ask if CocosCreator 2.4.2 is still supporting CANVAS html games still (instead of WEBGL)?

Thanks for your help in advance.

1 post - 1 participant

Read full topic


Problems with GPG implementation on Android

Extending Sprite Class

$
0
0

Hi

I have a class named MySprite which inherent Sprite and adds a bunch of properties to it.

Created a Factory class called createMySprite which calls
MySprite* theSprite = MySprite::create(“image.png”);

so I can continue to initialize theSprite.
I receive an error: *a value of type "cocos2d::Sprite * cannot be used to initialize an entity of type "MySprite "

What am I doing wrong ?

3 posts - 3 participants

Read full topic

libcocos2dx] Could not find libcocos2dx.apk!

$
0
0

I just get a very old project, then I get this error. I search the form but didn’t find a solution. I want to know how can I get more specific error. I read two thread in this forum, I think many reason can cause this error.

info:
cocos2d-x v3.12 lua
target android 5.1.1
windows 10

[2020-08-29 20:34:56 - MahjongClient] Android Launch!
[2020-08-29 20:34:56 - MahjongClient] adb is running normally.
[2020-08-29 20:34:56 - MahjongClient] Performing com.liuliugameCenter.sxmj.CCXGame activity launch
[2020-08-29 20:34:56 - MahjongClient] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2020-08-29 20:34:59 - MahjongClient] WARNING: Unknown device API version!
[2020-08-29 20:34:59 - MahjongClient] Uploading MahjongClient.apk onto device ‘3952093’
[2020-08-29 20:35:05 - MahjongClient] Installing MahjongClient.apk…
[2020-08-29 20:35:12 - MahjongClient] Success!
[2020-08-29 20:35:13 - libcocos2dx] Could not find libcocos2dx.apk!
[2020-08-29 20:35:13 - MahjongClient] Starting activity com.liuliugameCenter.sxmj.CCXGame on device 3952093
[2020-08-29 20:35:13 - MahjongClient] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.game.shengshi/com.liuliugameCenter.sxmj.CCXGame }

1 post - 1 participant

Read full topic

Cocos2dx build problem

Destructor called on a Sprite child when autorelease

$
0
0

Hi

I have an empty derived Sprite class.
I addChild to it another Sprite class I created (lets call it ChildSprite).

When I create the ChildSprite object, I do childSprite->autorelease();

However as soon as the program starts, the destructor of childSprite is called and I get an assert message “Node still marked as running on node destruction! Was base class onExit() called in derived class onExit() implementations?”

If I remove the autorelease, everything works.

Any ideas why ?

2 posts - 2 participants

Read full topic

Snake movements

$
0
0

any idea how to make a snake move with wave animation and can increase the length
same as this image
Layer 75

2 posts - 1 participant

Read full topic

Possible do 3d squeeze cards?


Facebook Live Video Cocos Creator

$
0
0

Good morning, do you know if currently for cocos creator V2.2 the Facebook Live Video service works, compiling for Android?

I follow the instructions on this page

https://docs.cocos.com/creator/manual/en/sdk/fb-an-and-live.html

Entry
fb.liveStream.startLive ();

But nothing happens

The difference I see is that in the pagian it indicates that a file named
fb-live-stream.js

But it is created with the extension
fb-live-stream.jsc

1 post - 1 participant

Read full topic

Fail to use HMS Analytic service

$
0
0

Good morning, I activate the HMS analysis service, taking this page as a reference

https://docs.cocos.com/creator/manual/en/cocos-service/hms-analytics.html

When compiling for android it generates this error

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘D:\apps\jsb-link\frameworks\runtime-src\proj.android-studio\app\build.gradle’ line: 7

  • What went wrong:
    A problem occurred evaluating project ‘:MP’.

Plugin with id ‘com.huawei.hms.plugin.analytics’ not found.

Is there something additional to configure?

1 post - 1 participant

Read full topic

Xcode build working BUT Android Studio build not working as expected

$
0
0

(I am new to Cocos2dx)
(Xcode with macOS, Android studio with Galaxy Note5)
macOS = Version 10.15.6
Xcode = Version 11.6
Android Studio = Version 4.0.1
Phone (Galaxy Note5) = samsung sm-n920k

I am making a stopwatch similar to https://cstimer.net.
The stopwatch is a cocos2d::Label* stopWatchLabel;
I am using the void update(float dt); function to update the stopwatch(Label) using the setString(); function.
It seems to work on Xcode. (Image below) (It is running)

But it doesn’t seem to work on Android Studio. As soon as I start the stopwatch, the program crashes. I think it’s because of the setString(); function. But I am not sure, and I can’t fix it.
How can I fix this code to make the stopwatch on Android?

HelloWorldscene.cpp

#include "HelloWorldScene.h"
#include "ui/CocosGUI.h"

#include <iostream>

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    auto scene = HelloWorld::create();
    auto layer = Layer::create();
    scene->addChild(layer);
    
    return scene;
}

// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Scene::init() )
    {
        return false;
    }

    auto visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 3. add your codes below...
    
    // colors for stopWatchLabel
    WHITE_4B = Color4B(255, 255, 255, 255);
    PINK_4B = Color4B(255, 0, 126, 255);
    GREEN_4B = Color4B(0, 255, 126, 255);
    
    stopWatchLabel = Label::createWithTTF("0.0->", "fonts/FiraCode-Regular.ttf", 96);
    stopWatchLabel->setPosition(Vec2(visibleSize.width/2+origin.x, visibleSize.height/2-100+origin.y));
    this->addChild(stopWatchLabel, 1);
    
    stopWatchBase = 0;
    this->scheduleUpdate();
    stopWatchCheck = 0; // 0: stopped, 1: started, 2: anti ovelap int usage, 3: stop with color
    touchDurationCheck = 0; // 0, 1->
    touchDurationBase = 0.0;
    holdStopWatch = 0.55;
    
    listener1 = EventListenerTouchOneByOne::create();

    listener1->onTouchBegan = [=](Touch* touch, Event* event){
        if (stopWatchCheck == 0)
        {
            stopWatchBase = 0;
            stopWatchLabel->setTextColor(PINK_4B);
            
            touchDurationCheck = 1;
        }
        else if (stopWatchCheck == 1)
        {
            stopWatchLabel->setTextColor(PINK_4B);
            stopWatchCheck = 0;
        }
        return true;
    };
    listener1->onTouchMoved = [=](Touch* touch, Event* event){
    };
    listener1->onTouchEnded = [=](Touch* touch, Event* event){
        if (stopWatchCheck == 2)
        {
            stopWatchCheck = 1;
        }
        stopWatchLabel->setTextColor(WHITE_4B);
        
        touchDurationCheck = 0;
        touchDurationBase = 0;
    };
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this);
    return true;
}
void HelloWorld::update(float dt)
{
    // stopWatchCheck to these
    if (stopWatchCheck == 1)
    {
        stopWatchBase += dt;
        stopWatchLabel->setString(std::to_string(stopWatchBase));
    }
    // touchDurationCheck
    if (touchDurationCheck == 1)
    {
        touchDurationBase += dt;
    }
    if (touchDurationBase > holdStopWatch && listener1->onTouchBegan)
    {
        stopWatchLabel->setString(std::to_string(stopWatchBase)); // if thing
        stopWatchLabel->setTextColor(GREEN_4B); // if thing
        stopWatchCheck = 2; // if thing
    }
}

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();
    
    // a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    
    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
    
    void update(float dt); // update function
    float stopWatchBase; // stopwatch base number thing
    cocos2d::Label* stopWatchLabel; // label to represent
    int stopWatchCheck;
    cocos2d::EventListenerTouchOneByOne* listener1; // touch listener
    int touchDurationCheck;
    float touchDurationBase; // touch duration
    float holdStopWatch; // hold to start
    
    cocos2d::Color4B WHITE_4B;
    cocos2d::Color4B PINK_4B;
    cocos2d::Color4B GREEN_4B;
};

#endif // __HELLOWORLD_SCENE_H__

2 posts - 2 participants

Read full topic

Custom Command in 4.0: How to draw a triangle strip

$
0
0

Hi there,
I am now updating to 4.0 and have problems updating my custom commands where I would do custom drawing.

Here is an example how I accomplished this in V3 -
I would create a custom command and draw my stuff in the callback function:

AnimatedTextureRender::AnimatedTextureRender(Size s, Texture2D *texture,bool stretchTexture){
    

    mTexture = texture;
    _stretchTexture = stretchTexture;
    setGLProgram(GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE));
    cocos2d::Texture2D::TexParams tp1 = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
    mTexture->setTexParameters(tp1);
    
    
    mTexture->retain();
    this->setContentSize(s);
    _s = s;
    autorelease();
    this->scheduleUpdate();
    
}




void AnimatedTextureRender::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags){
    mCustomCommand.init(_globalZOrder);
    mCustomCommand.func = CC_CALLBACK_0(AnimatedTextureRender::onDraw, this, transform, flags);
    renderer->addCommand(&mCustomCommand);
    
}



void AnimatedTextureRender::onDraw(const cocos2d::Mat4 &transform, uint32_t flags){
    
    
    auto glProgram = getGLProgram();
    glProgram->use();
    glProgram->setUniformsForBuiltins(transform);
    
    
    GL::bindTexture2D(mTexture->getName());
    GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION | GL::VERTEX_ATTRIB_FLAG_TEX_COORD);
    
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, _groundVectorData);
    glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, 0, _textureVectorData);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)4);
    
    CC_INCREMENT_GL_DRAWS(1);
        
    
    
}

Could anybody help me to convert this code to V4 @zhangxm, @slackmoehrle ?

I cannot really find a tutorial where this is explained in detail, looking into https://docs.cocos2d-x.org/cocos2d-x/v4/en/upgradeGuide/customCommandTutorial.html helped a bit - but was not enough for me to understand what I need to do.

Any help is appreciated :slight_smile:

1 post - 1 participant

Read full topic

Zooming out just a bit cause everything to disappear

$
0
0

Hi

I am trying to implement zoom out of perspective camera project using the mouse wheel.
Created a new default Cocos Hello World project and added a method in HelloWorldScene called
HelloWorld::initZoomListener
{
auto listener = EventListenerMouse::create();

    listener->onMouseScroll = ([](EventMouse* event)
        {
            auto cam = Camera::getDefaultCamera();
            auto z = cam->getPositionZ();

            if (event->getScrollY() > 0)
                cam->setPositionZ(z + 10);
            else if (event->getScrollY() < 0)
                cam->setPositionZ(z - 10);
        });

    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}

Thats it.
I’m calling initZoomListener in the scene init method.

Now the zoom works, however if you zoom out just a little bit, everything suddendly disappearing.

Anyone knows why ?

1 post - 1 participant

Read full topic

i have some problems Snake game

$
0
0

Firstly i am so sorry for my so bad english. :slight_smile: I am new on game developing and i try learn. I try writing a snake game, but have 2 problems for now. My first problem snake dont stable while on move and i when change the rotation,then the all body parts changing rotation but i want the part of body come to on head starting point rotation.
Some images on my problems;

My moving method;

void GameScene::snakeMove(float x,float y){
x=snakeHead->getPositionX();
y=snakeHead->getPositionY();
if(snakeHead->getRotation()==90 || snakeHead->getRotation()==270 ){
auto move = MoveBy::create(0.1f,
Vec2(-cos((snakeHead->getRotation())*M_PI / 180.0f)snakeHead->getContentSize().width/4SNAKE_BODY_SPACE,
-sin((snakeHead->getRotation())*M_PI / 180.0f)snakeHead->getContentSize().height/4SNAKE_BODY_SPACE));
snakeHead->runAction(move);
}
else {
auto move = MoveBy::create(0.1f,
Vec2(-cos((snakeHead->getRotation()+180)*M_PI / 180.0f)snakeHead->getContentSize().width/4SNAKE_BODY_SPACE,
-sin((snakeHead->getRotation()+180)*M_PI / 180.0f)snakeHead->getContentSize().height/4SNAKE_BODY_SPACE));
snakeHead->runAction(move);
}

if(snakeHead->getPositionX()>(origin.x+visibleSize.width)
   ||snakeHead->getPositionX()<origin.x
   ||snakeHead->getPositionY()>(origin.y+visibleSize.height)
   ||snakeHead->getPositionY()<origin.y)
Director::getInstance()->pushScene(TransitionFade::create(0,GameScene::createScene()));


  for (int i = 1; i < snakeSize; i++){

      auto move = MoveTo::create(0.1f, snakeBodyParts.at(i - 1)->getPosition());
      snakeBodyParts.at(i)->runAction(move);
    /*
      if(snakeBodyParts.at(i)->getPositionX()==x && snakeBodyParts.at(i)->getPositionY()==y){
          auto rotate = RotateTo::create(0.1f, snakeRotation);
          snakeBodyParts.at(i)->runAction(rotate);
      }*/ //I tried this for moving rotation but not working


  }

}

1 post - 1 participant

Read full topic

Run armature animation from old cocos studio project (*.ExportJson) in cocos creator?

$
0
0

I want to rebuild my game from cocos js with armature animation to cocos creator. How can I import that animations?

1 post - 1 participant

Read full topic


Loses object while reloading scene

$
0
0

hello all,
I got stuck at very strange issue or bug. I have almost completed my game. When I played it multiple times, I found out that when I m reloading scene like retrying game then I loses a object. Each and every other object is okay. What I am doing is I stored some paths of sprites in a vector and at runtime, generating a random number in the range of vector size then picking up that path and creating a sprite with that path. Sometimes it works but sometimes it doesn’t. Each step is working (like I have paths in vector, random number is generating, it picks path from vector) but sprite is not creating (sprite is null pointer as result in this case). And this issue is same for back button, i.e. when I press back button and again press play, Sometimes it loads sprite but sometimes it doesn’t.
Can someone please help me in this.
Thanks.

5 posts - 2 participants

Read full topic

Video player currenttime not working cocos creator

$
0
0

I am using creator 2.4.0
videoplayer.currenttime giving 0 until i tap on player;
i need the timer to give the value as soon as the video start playing.

any help?

2 posts - 2 participants

Read full topic

AudioSource loop not working.

$
0
0

Hi ! I made a 3D game and now I implementing the sound effects on it.
I followed this document:
https://docs.cocos.com/creator/manual/en/audio/audio.html

But I am facing an issue, I checked the loop option, But the sound is play only 1 time.
I also attached the screenshot of AudioSource component, The sound is play but only one time, Not in loop, I want to play it in loop.
Please help me out, I am looking forward to it. .
ss

1 post - 1 participant

Read full topic

Creator frozen in "Importing Assets"

$
0
0

It happened after some modification in a sub-project, then this project was copied into the main project.

There is any way of know what is causing this freeze? The menu bar works, but the engine never loads.

The engine console

1 post - 1 participant

Read full topic

Can't load debugging symbols on gdb

$
0
0

Hi, guys. I’m trying to compile my cocos2d-x cpp project with debugging symbols, so that I can debug it with gdb on vim, as I’m not a fan of IDEs. I’m doing so with the following command: cocos compile -m debug -p linux. However, after loading the binary onto gdb (with file bin/debug/linux/projectname), I get no results when I search for those symbols. For instance, when I run info types TypeName I get nothing returned to me. Furthermore, if I search for info on a function I’ve declared (with info functions NameSpace::TypeName::funcName), the name of that function and no additional info gets listed under the “Non-debugging Symbols section”, thus suggesting these symbols aren’t being attatched to my binary when compiling.

How can I actually get those symbols? If I were to compile some program directly with g++ I’d be able to just pass the -g flag, but how can I go about doing that with the cocos tool. If I’m not able to do this using the cocos tool, how can I go about compiling my game without it and without an IDE?

1 post - 1 participant

Read full topic

Viewing all 17056 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>