Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all 2747 articles
Browse latest View live

RenderTexture Transparent after transparent ColorLayer visit

$
0
0

@0mega wrote:

Hi everyone,

We're trying to render a RenderTexture which visits a few sprites and a semi transparent LayerColor node.

The structure is roughly like this:

renderTexture->begin();
background->visit(); //GREEN BACKGROUND FULLY OPAQUE
layercolor->visit(); //BLACK LAYERCOLOR(0,0,0,55) NODE
renderTexture->end();

The layercolor node is initialized with 55 transparency.
If I do NOT visit the layercolor the rendertexture will be fully opaque green.
If I visit the layercolor the rendertexture will be partially transparent, as if the rendertexture 'inherits' the transparency of the layercolor node.

Is there a way to prevent this? I am using the layercolor to 'darken' the background and I do not want the opacity level of the layercolor to apply to the entire 'final' image inside the renderTexture.

Thanks in advance.

Posts: 1

Participants: 1

Read full topic


Unable to compile android platform from terminal

$
0
0

@devilzk wrote:

Hi,

After a long gap, today I downloaded cocos studio and cocos2d-x 3.10. During setup first I faced issue due to older version of NDK (I had r8c). Then based on documentation I downloaded updated version from given link which is r11c (64bit).

Started setup from scratch and this time I was able to pass FILE_MISSING error of previous NDK version. However cpp-test compilation failed with two errors

/Users/devilzk/Study/hello-cocos/frameworks/runtime-src/proj.android/../../cocos2d-x/external/spidermonkey/prebuilt/android/armeabi/libjs_static.a(ExecutableAllocatorPosix.o):function JSC::ExecutableAllocator::determinePageSize(): error: undefined reference to '__page_size'

-- and --

/Users/devilzk/Study/hello-cocos/frameworks/runtime-src/proj.android/../../cocos2d-x/external/websockets/prebuilt/android/armeabi/libwebsockets.a(context.c.o):context.c:function libwebsocket_create_context: error: undefined reference to 'getdtablesize'

I tried changing version 4.8 to 4.9 in build_android.py, but that didn't help. Same error appear when I try to compile any cocos project as well. I am really not getting any clue how to get past this error and get APK file.

Thanks in advance.

Posts: 1

Participants: 1

Read full topic

GLSL shader crash only on samsung galax s3

$
0
0

@Marto wrote:

Hi to everyone,

I have this fragment shader .

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;

uniform float u_percent;

void main()
{
const float alpha = atan(v_texCoord.y - 0.5f, v_texCoord.x - 0.5f);
gl_FragColor = vec4(alpha,alpha,alpha, 1.f) * v_fragmentColor * texture2D(CC_Texture0, v_texCoord) ;
}

This shader works on Windows and ExperiaZ3 (Android 5.1), but crash on Samsung Galaxy S3 (Android 4.3).
I have assumption, it's because atan function, but i don't know how to fix it.

Posts: 8

Participants: 2

Read full topic

Number 1 is not centered when using createWithTTF

$
0
0

@ingtellect wrote:

I am using cocos2d-x 3.8.1 c++ version. I use few custom fonts (OpenSans family and DINNextRoundedLTPro-Bold) for my game. Most of things are fine but one thing is really annoying with createWithTTF and those fonts.
The thing is that the number 1 is not centered correctly. Using custom fonts, number 1 went right side and it's not center aligned. Arial font has same problem.
Here is code for reproduce.

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


Label* arial = Label::createWithTTF("arial", "fonts/arial.ttf", 20, Size::ZERO, TextHAlignment::CENTER);
Label* openSans = Label::createWithTTF("openSans", "fonts/OpenSans-Bold.ttf",20, Size::ZERO, TextHAlignment::CENTER);
Label* system = Label::createWithSystemFont("system", "", 20, Size::ZERO, TextHAlignment::CENTER);

arial->setPosition(Vec2(visibleSize.width/2 - 100, visibleSize.height/2 + 50));
openSans->setPosition(Vec2(visibleSize.width/2-100, visibleSize.height/2 ));
system->setPosition(Vec2(visibleSize.width/2-100, visibleSize.height/2 - 50));

this->addChild(arial);
this->addChild(openSans);
this->addChild(system);



Label* arialLabel = Label::createWithTTF("1", "fonts/arial.ttf", 40, Size::ZERO, TextHAlignment::CENTER);
LayerColor* arialBG = LayerColor::create(Color4B::GREEN);
arialBG->setContentSize(arialLabel->getContentSize());
arialLabel->addChild(arialBG,-1);

Label* openSansLabel = Label::createWithTTF("1", "fonts/OpenSans-Bold.ttf",40, Size::ZERO, TextHAlignment::CENTER);
LayerColor* openSansBG = LayerColor::create(Color4B::GREEN);
openSansBG->setContentSize(arialLabel->getContentSize());
openSansLabel->addChild(openSansBG,-1);

Label* systemLabel = Label::createWithSystemFont("1", "", 40, Size::ZERO, TextHAlignment::CENTER);
LayerColor* systemBG = LayerColor::create(Color4B::GREEN);
systemBG->setContentSize(arialLabel->getContentSize());
systemLabel->addChild(systemBG,-1);

arialLabel->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 + 50));
openSansLabel->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 ));
systemLabel->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2 - 50));

this->addChild(arialLabel);
this->addChild(openSansLabel);
this->addChild(systemLabel);

And here is screenshot.

Other numbers such as 2 are fine.

I could check the label string and adjust position for 1 but that's last thing I want to do.
Is there any solution for this?
Any advice would be appreciated.

Posts: 1

Participants: 1

Read full topic

cocos2d-x Richtext (auto) Align+Direction

$
0
0

@HadiAbbasi wrote:

hi guys
sorry for my english...
i want to make a chat box by cocos2d-x (c++) so the best tool for chat box items is richtext added in node containers which can contains text elements mixed by icons as stickers...so all i want to know is:
why cocos2d-x richtext can't set my text (auto or manual) direction and align like Label(at least the label shows it auto direction)? what should i do if i want to show true text align and direction when the user wants to send rtl language which contains stickers(or mixed rtl (right-to-left) words by ltr which contains stickers)?
i can push rtl or right aligned texts using ui::RichElementCustomNode but richtext won't make it totally auto direction and align...
in the other words, showing this message smile needs 3 element push:
1- in the other words, showing this message
2-:) sticker
3- needs 3 element push:
but when i send this message by RTL languages, i can't show my complete sentence correctly! cocos richtext watch it as 3 separated elements,not as unit element by unit align or direction...
thanks a lot...

Posts: 1

Participants: 1

Read full topic

cocos2d-x Richtext Real Height by content size

$
0
0

@HadiAbbasi wrote:

hi
sorry for my english...
i am developing a chatbox using cocos2d-x (c++) so the best textbox for mixed sentences with stickers is richtext...
as you know, one of the most important settings for chat item texts is word wrap, so the setting content size like Size(500,0) and setting ignoreContentAdaptWithSize(false) will help us to make it word wrap but i can't trace it's real height because it will shows the content size (500,0) forever...
in other words, growing the height of chat container will need to knowing the size of word wrap richtext and i can't trace it's true (real) size because it will show me just last adjusted content size!
thanks a lot...

Posts: 1

Participants: 1

Read full topic

Best way of moving physicsBody efficiently?

$
0
0

@nichlaspro132 wrote:

Hi again!

I have created a physics level consisting of boxes and one bigger box that refers to a player, as seen below:

I have implemented TouchBegin(attached to touchBegan) with the following code:

bool HelloWorld::onTouchBegin(Touch* touch, Event* event)
{
    edgeNode->runAction(MoveBy::create(1.0, Vec2(20,0)));
    return true;
}

So that the "player" will move a little to the right whenever the user is touching the screen but when the "player" reaches a box that blocks its way, it should stop but instead i can easily make the bigger box come through/inside the other physicsBodies.
Like this:


So my question is - How can i make this physicsBody move with perfect collision detection almost no matter the speed of the movement? Should i use another function or optimize something?

Thank you.
I appreciate your time!

Posts: 2

Participants: 2

Read full topic

Cocos creator from web development

$
0
0

@Ginfo wrote:

Hi everyone,

i am rails developer and i really like game development, it was a year with a first look cocos2d-JS but quickly i give up , now i start again with cocos create, i find it great tools for creation game in all platforms, i'm afraid to give up again, because i found just two good tutorial, now i need your advice to be a expert in cocos creator, and make first my game in iOS and android ,please give me the resources ,astuces, tricks, links ,whatever and thanks in advanced

Posts: 1

Participants: 1

Read full topic


Chipmunk: Too much overlap on collision

$
0
0

@compyler wrote:

Hello!

I have a little scene with boxes and a sphere (all are rendered via DrawNode). I.e. this is how I create the sphere:

drawNode = DrawNode::create();
drawNode->setName("Ball");
drawNode->setUserData( this );

drawNode->setPosition( position );

drawNode->drawSolidCircle(Vec2::ZERO, radius, 2.0f * M_PI, 20, color);

physicsBody = PhysicsBody::createCircle(radius, PhysicsMaterial(0.5f, 1.0, 0.0f));
physicsBody->setDynamic(true);
physicsBody->setCategoryBitmask( static_cast<int>(PhysicsCategory::Ball) );
physicsBody->setCollisionBitmask( static_cast<int>(PhysicsCategory::Barrier) );
physicsBody->setContactTestBitmask( PhysicsCategory::Barrier) | PhysicsCategory::Goal );

drawNode->setPhysicsBody( physicsBody );

level->getBackgroundLayer()->addChild(drawNode, zOrder);

The boxes are set up in a similar way. The only difference is, they are set to setDynamic(false) and the PhysicsBody is created as Box.
When the scene starts I move the Box (the DrawNode) via a MoveTo Action from top to bottom and I start to move the ball via ball->physicsBody->setVelocity( ballVelocity );

The problem is: When the box hits the movin ball, the ball is correctly pushed downwards, but there is a huge overlap! See this picture:

Why is there such a huge overlap? How can I make the collision without any overlap?

Posts: 2

Participants: 2

Read full topic

How to drag sprite from scrollview?

$
0
0

@cuongnmx wrote:

Hello,

I tried to drag a sprite from scrolling view but:
- Sprite was hidden moving out from scrollview
- When I disabled clipping: all the hidden parts of scrollview were shown => not what I want.

Does anyone know how to resolve this?

Posts: 3

Participants: 2

Read full topic

My ui buttons are not working when implemented on a scroll view

$
0
0

@kasweshi wrote:

This is how implemented my button
ui::Button * earth = ui::Button::create("MENU SELECT EARTH ONE.png", "MENU SELECT EARTH ONE.png");

then the event listener is as follows

earth->addTouchEventListener(CC_CALLBACK_1(LoadingScene::GoToGameScene, this));

when i use the normal button the callback works just fine i am able to move to the game scene but when i use the ui::button on the scrollview it just fails completely doesnt even give any error or crash. It doesnt respond to the event listener. Is there a way of adding the old MenuItemImage on a scrollview? or how can i make this work with the ui::button?

Posts: 6

Participants: 3

Read full topic

How to port CGRectInset to cocos2dx?

$
0
0

@Lem wrote:

Hi!

I'm soing the platformer tutorial that I found at Ray Wenderlich page:
https://www.raywenderlich.com/15230/how-to-make-a-platform-game-like-super-mario-brothers-part-1

And I have no idea how to port this method:

-(CGRect)collisionBoundingBox {
  CGRect collisionBox = CGRectInset(self.boundingBox, 3, 0);
  CGPoint diff = ccpSub(self.desiredPosition, self.position);
  CGRect returnBoundingBox = CGRectOffset(collisionBox, diff.x, diff.y);
  return returnBoundingBox;
}

Especialy the part with the CGRectInset and CGRectOffset frowning
Can someone guide me how to port this part of the code?

Posts: 2

Participants: 2

Read full topic

How to access collision forces in integrated chipmunk physics?

$
0
0

@atctrl wrote:

Hi all,

How one can access the collision forces and contact normal when using integrated Chipmunk of cocos2d-x v. 3.10? I think they are on collision arbiter of chipmunk and available in postsolve state but what would be a proper way to access them?

Best,
atctrl

Posts: 3

Participants: 2

Read full topic

Display PDF on Android - WebView on Android Issue: "Cross origin requests are only supported for protocol schemes: http, data, chrome, https."

$
0
0

@nov wrote:

I try to display PDF file on Android with using Cocos2Dx WebView component.
(Exactly experimental::ui:WebView component.)

Since Android WebView does not allow to display PDF files, there is needed to use java script code to display PDF file (pdf.js and few more files) for it.

The issue is that it displays following error:

04-26 16:03:06.556 27060-27060/com.dal.testproject I/chromium: [INFO:CONSOLE(0)] "XMLHttpRequest cannot load file:///android_asset/pdfviewer/Manual.pdf. Cross origin requests are only supported for protocol schemes: http, data, chrome, https.", source: file:///android_asset/pdfviewer/index.html?file=Manual.pdf (0)
04-26 16:03:06.586 27060-27060/com.dal.testproject I/chromium: [INFO:CONSOLE(3249)] "Uncaught TypeError: Cannot read property 'xhr' of undefined", source: file:///android_asset/pdfviewer/pdf.worker.js (3249)
04-26 16:03:07.096 27060-27060/com.dal.testproject I/chromium: [INFO:CONSOLE(106)] "Warning: Unhandled rejection: Unexpected server response (0) while retrieving PDF "file:///android_asset/pdfviewer/Manual.pdf".", source: file:///android_asset/pdfviewer/pdf.js (106)

So I tried to find a solution for it and found that this could solve the "Cross origin requests" issue.

Based on this I should set WebViewSettings as following:

// settings for webview
mWebView = (WebView)findViewById(R.id.activity_main_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAllowContentAccess(true);
mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);

But how to do that from Cocos2D-x C++ code, when I have direct access only to Cocos2D-x WebView component and do not have direct access to underlying Android WebView, please?

Posts: 1

Participants: 1

Read full topic

Spine (slow loading)

$
0
0

@esben_lundsager wrote:

Hi does anyone know if the current spine implementation in cocos2dx-v3 support binary load - or still only json load?

Thanks
Esben

Posts: 1

Participants: 1

Read full topic


Incorrectly scrolling sprites on iPhone simulator

$
0
0

@cuongnmx wrote:

I'm trying to scroll sprite inside a scrollview. The sprites "delay" on screen as in picture bellow (each column contains 5 cards only).
I know simulator is not powerful as real device. I did not test on iPhone device but there maybe some way to fix this even on simulator?

Posts: 2

Participants: 1

Read full topic

Manually drain autorelease pool for scene transition?

$
0
0

@matthewlehew wrote:

When a scene is replaced, when is the old scene actually released? Also, is there a command to manually drain the autorelease pool?

Context: I've developed an endless runner that relies on being able to quickly start a new game after the game ends. This is handled by utilizing replaceScene(); and replacing the scene with a new version of itself. When this is done, animations and some data elements are all rebuilt. However, all textures and sounds are loaded into the cache from the app delegate, so those resources don't have to be reloaded.

The problem I'm having is that when the scene is rebuilt, about a second after the scene displays I notice a couple dropped frames. This is the only time it occurs, and I can't figure out what's causing it. It's consistent and reproducible, and only occurs AFTER the scene is rebuilt, NEVER on the first play through. None of my code is executing at this point, and everything is loaded. If the player starts running immediately when the scene is loaded, the dropped frame or two can result in a quick loss. The only way to avoid it is to wait a couple seconds after the scene is rebuilt before starting.

I've run the app through Instruments, and while I can't prove it, my suspicion is that releaseScene() invokes the release() command for all of the old scene's assets, and I think this means that the resources are marked to be removed next time the autorelease pool is drained. Is it possible that the pool drains roughly a second after the new scene is loaded? I would be puzzled, because there isn't too much to the scene when you take out the textures and sounds, so I don't know why releasing the memory would cause a dropped frame (unless releasing a bunch of listeners is memory intensive).

My theory to test this would be to have the pool drain immediately when the new scene is finished loading (before the user can start the game again). Is there a function to drain the game's pool?

More importantly, does this theory make any sense at all?

Posts: 9

Participants: 4

Read full topic

Where is the grid view?

$
0
0

@shipit wrote:

Hey Guys,

How do I go about implementing a grid view? I've got table view to work as a list etc. And Cocos Creator has an awesome UI widget that does grid view looks like -- so is that available under extensions?

Thanks!

Posts: 1

Participants: 1

Read full topic

[SOLVED]Import Box2dTestbed from samples to project?

$
0
0

@nichlaspro132 wrote:

In this directory ...\cocos2d-x_3-9\tests\cpp-tests\Classes\Box2DTestBed, there is files for the testbed working in cocos2d-x.
But the problem is that I have no idea about how I should use them in my project or just in a place where I can take the files in use. Any idea?

Thanks!

Posts: 1

Participants: 1

Read full topic

Windows Phone 8.1 build Store error

$
0
0

@C7an wrote:

I use ver 3.10 (checkout from github). It run normaly on simulator and no error. But when i build store release, it error like this:

Anybody helpme please cry
Sorry for my poor English frowning

Posts: 1

Participants: 1

Read full topic

Viewing all 2747 articles
Browse latest View live