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

Any easy way to import cocos2d v3.17 javascript into cocos creator?

$
0
0

Hello guys, i have an old game project written in cocos2d-html the game is compile for android using android studio (cocos2d-x 3.17) , is ay easy way to import / upgrade this project into cocos creator?
cheers

3 posts - 2 participants

Read full topic


Cross Platform Tips From The Cocos Team

Crop or mask image

$
0
0

Hi, i did crop image like this and with is coed.
Original Image:
images
Crop Image:
croping
crop image with green background.

Code:
clipper content size width and height

        var width = 200, height = 200, winSize = cc.winSize;

        var stencil = new cc.DrawNode();
        stencil.drawCircle(cc.p(width/2, height/2), 40, 0, 200, 0, 100, cc.color(255, 255, 255, 255));

        var clipper = new cc.ClippingNode(stencil);
        clipper.setContentSize(width, height);
        clipper.setAnchorPoint(0.5, 0.5);
        clipper.setPosition(winSize.width/2, winSize.height/2);
        this.addChild(clipper);

        var avatar = cc.Sprite.create(res.image);
        avatar.setPosition( clipper.width / 2, clipper.height / 2);
        avatar.setAnchorPoint(0.5, 0.5);
        clipper.addChild(avatar);

Here I have a two problems:

  • when I am tray to create 6 crop images I got this Waring?
    Failed to allocate buffer for DrawNode: buffer for 64 vertices requested

  • is there any best or simple way to crop images?

1 post - 1 participant

Read full topic

Tutorial - Adding a texture to your lines

$
0
0

If you’ve been playing a game with a bridge, a rope, a snake, or another line with a texture, you may be wondering how you can do the same for your game. Our star writer, Baiyu Wubing, from the Chinese forums, shared this great tutorial on how to do the same for your game.

First, here is his example.

Let’s start by creating a scene cc.Graphics node and add a child node cc.Sprite, and change the rendering mode to Mesh.

Because Mesh coordinates are calculated from the top left corner, and the Graphics drawing is drawn from the center.

So cc.Spritenode, Scaleadjust (1,-1), Anchor adjust (0,1).

In order to make sure the texture is filled after repeating beyond the boundary, the obtained texture size has to be a perfect square and set Repeat.

The drawing texture definitely needs some coordinate position information.

Take a look at the Graphics of WebGL realization.

Graphics has an a _impl variable.

That _impl also has a _paths variable, the points of all objects recorded paths, and a corresponding image line.

While lineTo and moveTo will go to _paths stuffing data points to draw the line.

For the circle and arc and rect, other interfaces eventually calls lineTo and moveTo.

So with this _paths we draw the texture, you can traverse the first point out.

for( let index = 0; index < _impl._paths.length; index++) {
    const path = _impl._paths[index];
    const pathPoints = path.points;
    if (pathPoints.length < 2) continue;
    for(let index2 = 1; index2 < pathPoints.length; index2++) {
        // current point
           const p = cc.v2(pathPoints[index2].x, pathPoints[index2].y);
       // previous point
           const p_pre = cc.v2(pathPoints[index2 - 1].x, pathPoints[index2 - 1].y);
           }
 }

Now, how to paint with texture?

First, consider two adjacent points, then according to the line width of w for rectangle painting. The rectangle has four points, and we ask for the coordinates of these four points.

Now calculate the direction of these two points.

const dir = p.sub(p_pre); // direction

Then find a vector in the vertical direction (calculated based on the inner vector product being 0) of the length is half the line width.

const cross_dir = (dir.y == 0 ? cc.v2(0, 1) : cc.v2(1, -dir.x / dir.y).normalize()).mulSelf(w / 2); // Vertical direction

The four vertices of this rectangle can be obtained from the two points and the vertical direction.

const p_r_t = p.add(cross_dir); // upper right
const p_r_b = p.sub(cross_dir); // upper left
const p_l_t = p_pre.add(cross_dir); // bottom right
const p_l_b = p_pre.sub(cross_dir); // bottom left

The last four points padding sprite.spriteFrame data vertices, if it is not understood, reference this article Preliminary grid sprite rendering mode! (Chinese only)

For uv texture coordinates, vertex coordinates used here directly a scaling factor. The reference code is as follows.

const uv_mul = 50;
const i_offset = vertices.x.length;
vertices.x.push(p_r_t.x, p_r_b.x, p_l_t.x, p_l_b.x);
vertices.y.push(p_r_t.y, p_r_b.y, p_l_t.y, p_l_b.y);
vertices.nu.push(p_r_t.x / uv_mul, p_r_b.x / uv_mul, p_l_t.x / uv_mul, p_l_b.x / uv_mul);
vertices.nv.push(p_r_t.y / uv_mul, p_r_b.y / uv_mul, p_l_t.y / uv_mul, p_l_b.y / uv_mul);
vertices.triangles.push(i_offset + 0);
vertices.triangles.push(i_offset + 1);
vertices.triangles.push(i_offset + 2);
vertices.triangles.push(i_offset + 1);
vertices.triangles.push(i_offset + 2);
vertices.triangles.push(i_offset + 3);

There is a problem with drawing rectangles in this way. For drawing arcs, if the separation is too large, or the line width is relatively large, separation will occur.

78bac3cce2fbe0213771ce1dc1b75f6363f71728

So how to deal with this gap?

Just draw a circle at the connection point so that the gap can be removed.

02-02

So how to draw a circle? A circle can be regarded as a regular polygon, and the position coordinates can be confirmed according to the relationship between the radius and the center of the circle. Please refer to the special loading effects of shader animation! article to learn more. (Chinese only)

13-11

The radius is exactly half the width of the line. The coordinates on a circle are converted into the following code.

//angle
const r = 2 * Math.PI * index3 / count;
// Calculate the direction vector first, and add the coordinates of the center of the circle to the point on the circle.
const pos_circle = cc.v2(w / 2 * Math.cos(r), w / 2 * Math.sin(r)).addSelf(p);

How to determine the vertex index?

In fact, you can follow the center of the circle and draw triangles one by one.

Of course, this is one of the indexing methods, converted into the code as follows.

// Drawing a circle
const count = 12;
i_offset = vertices.x.length;
vertices.x.push(p.x);
vertices.y.push(p.y);
vertices.nu.push(p.x / uv_mul);
vertices.nv.push(p.y / uv_mul);
for (let index3 = 0; index3 < count; index3++) {
      const r = 2 * Math.PI * index3 / count;
      const pos_circle = cc.v2(w / 2 * Math.cos(r), w / 2 * Math.sin(r)).addSelf(p);
      vertices.x.push(pos_circle.x);
      vertices.y.push(pos_circle.y);
      vertices.nu.push(pos_circle.x / uv_mul);
      vertices.nv.push(pos_circle.y / uv_mul);
      if (index3 === 0) {
               // 0 - count -1
               vertices.triangles.push(i_offset, i_offset + 1 + index3, i_offset + count);
                } else {
               // 0 - index3 - (index3-1)*
               vertices.triangles.push(i_offset, i_offset + 1 + index3, i_offset + index3);
        }
}

The above is just to achieve the effect of simple drawing texture. If you want to achieve the effect of rope, you need to recalculate the texture coordinates, which are related to the position/direction/length.

02-04

Realization principle

Several front lines drawing texture has been achieved; the main goal is to calculate the correct uv coordinates.

Because this line has a direction and a length, it will affect the calculation of texture coordinates.

One idea here thinks that pulling all the line segments into a straight line and place them in one direction.

In order to make this texture move from the head from the tail, after straightening, the last point is used as the starting point of the texture.

So when traversing this point, start from the end and record the length of each section.

09-06

Texture coordinates v two points are 0and 1. The texture coordinates u(horizontal direction) are calculated based on the length of the rope.

// Calculate from the last point
for (let index2 = pathPoints.length - 1; index2 > 0; index2--) {
      // Omit part of the code
      vertices.x.push( **p_r_t** .x, p_r_b.x, **p_l_t** .x, p_l_b.x);
      vertices.y.push( **p_r_t** .y, p_r_b.y, **p_l_t** .y, p_l_b.y);
      // Calculate uv
      vertices.nu.push(offsetX.x * uv_mul, offsetX.x * uv_mul, (offsetX.x + dirLen) * uv_mul, (offsetX.x + dirLen) * uv_mul);
      vertices.nv.push(1, 0, 1, 0);
      // Omit part of the code
      offsetX.addSelf(cc.v2(dirLen, 0)); *//* *Record the length of the drawing*
}

One problem with this backward traversal is that the head will cover the texture of the tail.

09-07

So after calculating the vertex index of the rectangle, it needs to be reversed as a whole and let him draw from the beginning. The main code is as follows.

let trianglesCache: number[ ][ ] = [ ];
for ( let index2 = pathPoints.length - 1; index2 > 0; index2--) {
      // Omit part of the code
      triangles.push(i_offset + 0);
      triangles.push(i_offset + 1);
      triangles.push(i_offset + 2);
      triangles.push(i_offset + 1);
      triangles.push(i_offset + 2);
      triangles.push(i_offset + 3);
      trianglesCache.push(triangles);
}
trianglesCache.reverse(); //Vertex index inversion
trianglesCache.forEach(v => {
      //True vertex index order
      vertices.triangles.push(...v)
}

After inversion, the texture of the rope is correct.

09-08

For drawing a circle at the connection (actually a polygon), you need to pay attention to the rotation of each point so that the texture direction of the circle is correct.

09-09

The reference code is as follows.

// Draw a circle
const dir_angle = dir.signAngle(cc.v2(-1, 0)); //The included angle with the negative direction of the x-axis
const count = 12;
i_offset = vertices.x.length;
// Here is the center of the circle
vertices.x.push(p.x);
vertices.y.push(p.y);
vertices.nu.push(offsetX.x * uv_mul);
vertices.nv.push(0.5);
for (let index3 = 0; index3 < count; index3++) {
       const** r = 2 * Math.PI * index3 / count;
       //Vector from center to each side
       const pos_circle = cc.v2(w / 2 * Math.cos(r), w / 2 * Math.sin(r));
       vertices.x.push(pos_circle.add(p).x);
       vertices.y.push(pos_circle.add(p).y);
       // Need to rotate for round uv
       vertices.nu.push((pos_circle.rotate(dir_angle).x + offsetX.x) * uv_mul);
       vertices.nv.push(pos_circle.rotate(dir_angle).y / w + 0.5);
       if (index3 === 0) {
              triangles.push(i_offset, i_offset + 1 + index3, i_offset + count);
              } else {
                     triangles.push(i_offset, i_offset + 1 + index3, i_offset + index3);
              }
}

Finally, let me draw a star for everyone~

09-10

Summary

The whole idea of ​​the rope texture is to convert all the curved lines into straight, and then calculate the texture coordinates.

The above is using Cocos Creator v2.3.3. I hope this helps you a little and welcome to share with friends around you.

Check out this and my other tutorials in my GitHub.

1 post - 1 participant

Read full topic

Suggestion: Don't autosync this folder

$
0
0

If it is possible, would be great an checkbox in the folders (like there is the “is bundle”), to skip this folder in autosync when the creator is highlighted again.

I have projects that the creator freezes like 30s or more, and most of the assets are inside a specific folder, so skip it and only sync when asked for and/or on the engine load would be great.

1 post - 1 participant

Read full topic

Generating APK build error android studio

$
0
0

Hey all,

I have a ready application. I can use it by running from android studio but while generating apk for it, I got a build error

Build command failed.
Error while executing process C:\Users\itsme\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Development\android cocos games\Jump\cocos2d\cocos\platform\android\libcocos2dx\.cxx\cmake\debug\x86_64 MyGame}
ninja: Entering directory `C:\Development\android cocos games\Jump\cocos2d\cocos\platform\android\libcocos2dx\.cxx\cmake\debug\x86_64'

ninja: error: '../../../../../../../../external/Box2D/prebuilt/android/x86_64/libbox2d.a', needed by '../../../../build/intermediates/cmake/debug/obj/x86_64/libMyGame.so', missing and no known rule to make it

here is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()

    defaultConfig {
        applicationId "org.cocos2dx.Jump"
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"

        externalNativeBuild {
            cmake {
                targets 'MyGame'
                arguments "-DCMAKE_FIND_ROOT_PATH=", "-DANDROID_STL=c++_static", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE"
                cppFlags "-frtti -fexceptions -fsigned-char"
            }
        }

       ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
        
    }

    sourceSets.main {
        java.srcDir "src"
        res.srcDir "res"
        manifest.srcFile "AndroidManifest.xml"
        assets.srcDir "../../Resources"
    }

    externalNativeBuild {
        cmake {
            path "../../CMakeLists.txt"
        }
    }

    signingConfigs {

       release {
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    buildTypes {
        release {
            debuggable false
            jniDebuggable false
            renderscriptDebuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (project.hasProperty("RELEASE_STORE_FILE")) {
                signingConfig signingConfigs.release
            }
        }

        debug {
            debuggable true
            jniDebuggable true
            renderscriptDebuggable true
        }
    }
    ndkVersion '21.0.6113669'
}

android.applicationVariants.all { variant ->
    def project_root_folder = "${projectDir}/../.."
    def dest_assets_folder = "${projectDir}/assets"

    // delete previous files first
    delete dest_assets_folder
    def targetName = variant.name.capitalize()
    def copyTaskName = "copy${targetName}ResourcesToAssets"
    
    tasks.register(copyTaskName) {
        copy {
            from "${buildDir}/../../../Resources"
            into "${buildDir}/intermediates/assets/${variant.dirName}"
            exclude "**/*.gz"
        }
    }
    tasks.getByName("pre${targetName}Build").dependsOn copyTaskName
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':libcocos2dx')
}

Can someone please help me
Thanks in advance.

5 posts - 2 participants

Read full topic

HowTo: Build for Apple tvOS ?

$
0
0

Please provide instructions on how to build for Apple tvOS - your documentation appears non-existent here and there is little to no useful information I could find online.

2 posts - 2 participants

Read full topic

Circular dependency / referencing in typescript

$
0
0

I have 3 classes (A, B, C)
A.ts

import B from "./B";
const {ccclass, property} = cc._decorator;
@ccclass
export default class A extends cc.Component {
    @property(B)
    refB: B = null;
}

B.ts

import C from "./C";
const {ccclass, property} = cc._decorator;
@ccclass
export default class B extends cc.Component {
    @property(C)
    refC: C = null;
}

C.ts

import A from "./A";
const {ccclass, property} = cc._decorator;
@ccclass
export default class C extends cc.Component {
    @property(A)
    refA: A = null;
}

due to circular dependency / referencing, either refA / refB/ refC will be null in IDE. how to fix this problem in typescript?

2 posts - 2 participants

Read full topic


Can I use ApplyImpulse along World Coordinates axes?

$
0
0

Hi,
I have a player that is holding and rolling a barrel in front of him.
I want to be able to throw the barrel vertically. I use the applyImpulse function.
The problem is, as the barrel is rotating so is it’s coordinate system. So I cannot know which direction to throw the barrel in. Instead of using the local coordinates I would like to throw the barrel along the world’s y-axis. Is there a way to do that?

1 post - 1 participant

Read full topic

Physics Running Faster in Browser

$
0
0

I’m having a strange problem, the physics in my game is running faster in a browser than it is in the simulator. In my game, I can aim in 360 degrees and fire off a shot. The shot (a rigidbody attached to a sprite, not a bullet) is always given the same speed, and is fired off in the direction the player aimed. The shot is moved by setting its linear velocity. I have an array of unit vectors for each degree in all 360 degrees, and I multiply the unit vector by my speed (set to 500 always) to calculate velocity.

In the simulator, everything looks as I expect. In the browser, the shot moves way faster than I expect. I placed some log statements and found out how far the shot fires the first frame after velocity is applied:

Shot position after frame 1 (Simulator): (-2.58, 7.93, 0.00) dt: 0.016667999999999666

Shot position after frame 1 (Browser): (-2.22, 8.03, 0.00) dt: 0.006881000000000313

This is a 2D game so I’ll ignore z values. In the simulator the shot moves from (0, 0) to (-2.58, 7.93) in 0.01667 seconds (60fps). This is what I expect, the distance traveled is 7.717 , the frames per second is 60.

Looking at the browser, the shot moves from (0, 0) to (-2.22, 8.03). A similar distance traveled of 7.499, however it did so in 0.006881 seconds. It traveled almost the same exact distance in one frame at 145fps in the browser as it did in 60fps in the simulator.

I’ve tried to cap the frame rate to 60fps in the browser by calling:

cc.game.setFrameRate(60);

But that doesn’t seem to have an effect on anything.

Am I doing something wrong? This behavior makes no sense to me, I feel like the fix is something completely obvious that I’m missing here. Any help would be appreciated, thanks!

1 post - 1 participant

Read full topic

Is cocos2d-x still being maintained?

$
0
0

Hi…

I really present my apologies about the topic, but i’m wondering what is the future of Cocos2d-x, first, i need to say this engine is really confortable, and of course seems to be in a very mature state, so sometimes i wonder myself : Myself… maybe there is no more update because the engine works flawlessly and does not require more maintenance… And that has some sense since a 2D game really does not has much things to take in mind than some sprites, sounds and inputs (not at least as a 3d game that cover a lot of more topics like shaders and so)…

Could we say Cocos2d-x does not needs more maintenance?..

Greetings.

4 posts - 2 participants

Read full topic

Rotate Sprite3D by World Axis, not Local Axis

$
0
0

Cocos2d-x
Is there any way to rotate a Sprite3D object by World Axis?

3 posts - 1 participant

Read full topic

CLI Build on Docker Windows

$
0
0

Hi,

I have got quite far in building a web-mobile game with a windows docker container, but the build gets stuck at this stage:

When I run this without a docker container I can pass this stage and when I’m looking at the CLI output I think it gets stuck on build jsb-adapter.

Locally CLI output logs from same place in the build where it passes to the next stages instead of timing out:
image

@jare I’m tagging you because I think you have some nice input here in trying to get me further into the build, cause I’m pretty stuck at this stage.

I’m building on currently latest windows 10 docker container:
mcr.microsoft.com/windows:2004

Any ideas?

1 post - 1 participant

Read full topic

HSV color modifier

$
0
0

Hello,
I’m trying to change a sprites hue value using a js code
Here is what I want:
image

I looked up in the documentation but couldn’t find something that works perfectly as I wanted.
A link or an answer would be really nice :slight_smile:

2 posts - 2 participants

Read full topic

How to see console.log on Facebook Instant Games Android?

$
0
0

Is there any way to see the output of console.log when running the game on Facebook Instant Games - Android platform?

I am looking at adb logcat but the cocos logs don’t show up there. Any ideas?

2 posts - 2 participants

Read full topic


Cocos Showcase - September 2020

$
0
0

A new showcase of Cocos games has appeared for you to check out! If you want to be a part of the next showcase, message us, and share your game. Your game must be 100% complete or being released in the same month in which we release a new showcase video.

Watch it on YouTube

1 post - 1 participant

Read full topic

how to disable label's anti aliasing

$
0
0

I want to get a label with a clear outline.
Mobile devices also display labels with blurred edges, like on windwos.

I tried several methods, but either they weren’t valid anymore or there were only ways to turn off texture anti-aliasing.


As in this post, calling setAliasTexParameters() of Label’s FontAtlas also gives blurry results.


This method also doesn’t work.

If the edges of the label are not clear, the game will look messy overall. Is there any solution?
Thank you for reading!! :heart_eyes:

1 post - 1 participant

Read full topic

Physics Body spawns at wrong location

$
0
0

Hi,
I have a problem due to my Physics Body spawning at (0, 0) when I create an enemy.

My game is a sidescroller where the enemies walk from right to left and on the left side of the screen I use a raycast to check whether an enemy has reached its destination. So now I have the problem that the enemies reach their destination immediately when they spawn instead of when they reach the left side of the screen by walking there.

My inheritance hierarchy is as follows:
Scene -> AutoScrollerClass -> ScreenToBeScrolled (inherits Node) -> EnemyClass (inherits Node) -> Sprite (which has the PhysicsBody component)

I set the position and scale of the EnemyClass, but when I create the PhysicsBody and add it to the sprite (which is at this point not child of the enemy class yet) it spawns in the bottom left corner of the screen ((0,0) of the Scene I imagine) and only then gets moved to its proper location. How can I avoid this?

PS: I tried setting the position and scale of the sprite instead, but it didn’t help.

2 posts - 2 participants

Read full topic

Cocos2dx Sqlite Sqlcipher

Cocos2dxDownloader.nativeOnProgress - crash on different android versions

$
0
0

Hello there,
I’m using 3.17.2 version of Cocos2dx engine.
When app is in background and download is started I’m getting this bug report in Firebase.

Fatal Exception: java.lang.UnsatisfiedLinkError

No implementation found for void org.cocos2dx.lib.Cocos2dxDownloader.nativeOnProgress(int, int, long, long, long) (tried Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnProgress and Java_org_cocos2dx_lib_Cocos2dxDownloader_nativeOnProgress__IIJJJ)

Any help is appreciated.
Thanks!

1 post - 1 participant

Read full topic

Viewing all 17052 articles
Browse latest View live


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