bool jsb_Effect3DOutline_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; Effect3DOutline* cobj = new (std::nothrow) Effect3DOutline(); cobj->init(); cobj->autorelease(); TypeTest<Effect3DOutline> t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); auto typeMapIter = _js_global_type_map.find(typeName); CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; CCASSERT(typeClass, "The value is null."); JS::RootedObject proto(cx, typeClass->proto.ref()); JS::RootedObject parent(cx, typeClass->parentProto.ref()); JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t* p = jsb_new_proxy(cobj, obj); AddNamedObjectRoot(cx, &p->obj, "cocos2d::Effect3DOutline"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; }
Effect3DOutline* Effect3DOutline::create() { Effect3DOutline* effect = new (std::nothrow) Effect3DOutline(); if(effect && effect->init()) { effect->autorelease(); return effect; } else { CC_SAFE_DELETE(effect); return nullptr; } }
bool jsb_Effect3DOutline_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; Effect3DOutline* cobj = new (std::nothrow) Effect3DOutline(); cobj->init(); js_type_class_t *typeClass = js_get_type_from_native<Effect3DOutline>(cobj); JS::RootedObject jsobj(cx, jsb_ref_create_jsobject(cx, cobj, typeClass, "Effect3DOutline")); args.rval().set(OBJECT_TO_JSVAL(jsobj)); if (JS_HasProperty(cx, jsobj, "_ctor", &ok) && ok) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(jsobj), "_ctor", args); return true; }
void Sprite3DWithSkinOutlineTest::addNewSpriteWithCoords(Vec2 p) { std::string fileName = "Sprite3DTest/orc.c3b"; auto sprite = EffectSprite3D::create(fileName); Effect3DOutline* effect = Effect3DOutline::create(); effect->setOutlineColor(Vec3(1,0,0)); effect->setOutlineWidth(0.01f); sprite->addEffect(effect, -1); Effect3DOutline* effect2 = Effect3DOutline::create(); effect2->setOutlineWidth(0.02f); effect2->setOutlineColor(Vec3(1,1,0)); sprite->addEffect(effect2, -2); sprite->setScale(3); sprite->setRotation3D(Vec3(0,180,0)); addChild(sprite); sprite->setPosition( Vec2( p.x, p.y) ); auto animation = Animation3D::create(fileName); if (animation) { auto animate = Animate3D::create(animation); bool inverse = (std::rand() % 3 == 0); int rand2 = std::rand(); float speed = 1.0f; if(rand2 % 3 == 1) { speed = animate->getSpeed() + CCRANDOM_0_1(); } else if(rand2 % 3 == 2) { speed = animate->getSpeed() - 0.5 * CCRANDOM_0_1(); } animate->setSpeed(inverse ? -speed : speed); sprite->runAction(RepeatForever::create(animate)); } }
bool js_cocos2dx_Effect3DOutline_setOutlineColor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); Effect3DOutline* cobj = (Effect3DOutline *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineColor : Invalid Native Object"); if (argc == 1) { cocos2d::Vec3 arg0; ok &= jsval_to_vector3(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Effect3DOutline_setOutlineColor : Error processing arguments"); cobj->setOutlineColor(arg0); args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_cocos2dx_Effect3DOutline_setOutlineColor : wrong number of arguments: %d, was expecting %d", argc, 1); return false; }
void Sprite3DEffectTest::addNewSpriteWithCoords(Vec2 p) { //option 2: load obj and assign the texture auto sprite = EffectSprite3D::createFromObjFileAndTexture("Sprite3DTest/boss1.obj", "Sprite3DTest/boss.png"); Effect3DOutline* effect = Effect3DOutline::create(); sprite->addEffect(effect, -1); effect->setOutlineColor(Vec3(1,0,0)); effect->setOutlineWidth(0.01f); Effect3DOutline* effect2 = Effect3DOutline::create(); sprite->addEffect(effect2, -2); effect2->setOutlineWidth(0.02f); effect2->setOutlineColor(Vec3(1,1,0)); //sprite->setEffect3D(effect); sprite->setScale(6.f); //add to scene addChild( sprite ); sprite->setPosition( Vec2( p.x, p.y) ); ActionInterval* action; float random = CCRANDOM_0_1(); if( random < 0.20 ) action = ScaleBy::create(3, 2); else if(random < 0.40) action = RotateBy::create(3, 360); else if( random < 0.60) action = Blink::create(1, 3); else if( random < 0.8 ) action = TintBy::create(2, 0, -255, -255); else action = FadeOut::create(2); auto action_back = action->reverse(); auto seq = Sequence::create( action, action_back, nullptr ); sprite->runAction( RepeatForever::create(seq) ); }