Cocos2d-x network::HttpRequest - Why I should pass Layer* to setResponseCallback?

StackOverflow https://stackoverflow.com/questions/23620425

  •  21-07-2023
  •  | 
  •  

سؤال

    HttpRequest* request = new HttpRequest();
    request->setUrl("http://just-make-this-request-failed.com");
    request->setRequestType(HttpRequest::Type::GET);
    request->setResponseCallback(this, httpresponse_selector(HttpClientTest::onHttpRequestCompleted));

This code is from the NetworkTest of cocos2d-x 3.0. I don't understand why I should pass Layer* to setResponseCallback? What if I want to send/get request/response without creating a single layer? Why shouldn't I be able to do that?

هل كانت مفيدة؟

المحلول

Selector in obj-c is just the name of the method so in order to call it you need a reference to the object as well. The code calls it "httpresponse_selector" and cocos2d-x is reportedly modelled after obj-c so might be it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top