Skip to content

How to use DynamicLight? #51

Description

@ttohin

I didn't find examples how to use avalon::graphics::DynamicLight and I created empty project with HelloWorld::init method like this.
So, I don't see dynamic lighting and/or shadows from sprite baba.png

bool HelloWorld::init()
{
  if ( !Layer::init() )
  {
    return false;
  }
  Size visibleSize = Director::getInstance()->getVisibleSize();
  Vec2 origin = Director::getInstance()->getVisibleOrigin();

  auto bg = Sprite::create("HelloWorld.png");

  // position the sprite on the center of the screen
  bg->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
  bg->setScale(2, 2);

  // add the sprite as a child to this layer
  this->addChild(bg);

  auto baba = Sprite::create("baba.png");
  baba->cocos2d::Node::setPosition({visibleSize.width/2, visibleSize.height/2});
  this->addChild(baba);

  auto dynamicLight = avalon::graphics::DynamicLight::create();
  dynamicLight->debugDrawEnabled = true;
  dynamicLight->setShadowCasters(*baba);
  dynamicLight->setPosition({visibleSize.width/2 + 40, visibleSize.height/2});
  this->addChild(dynamicLight);

  return true;
}

Main question is. What do I wrong?

And another ones about signature of method:

void DynamicLight::setShadowCasters(Node& casters) 

Why casters is reference? Do we really need in copying here? And why casters are plural (may be list of Nodes expected here)?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions