# Include "cocos2d. H "using_ns_cc; Class gamescene: Public cocos2d: layer {public: static cocos2d: Scene * createscene (); Virtual bool Init (); void menucallback (ref * psender ); create_func (gamescene); // reload the draw method virtual void draw (Renderer * Renderer, const mat4 & transform, uint32_t flags) override; protected: // custom draw implements void ondraw (const cocos2d: mat4 & transform, bool transformupdated); cocos2d: customcommand _ customcommand; private: // note that the auto keyword size cannot be used; sprite * sprite ;};
// Created by jacedy on 14-8-11. # include "gamescene. H "using_ns_cc; cocos2d: Scene * gamescene: createscene () {auto scene = scene: Create (); // create a scenario auto layer = gamescene :: create (); // create a layer scene-> addchild (layer); Return scene;} // initialize the current layer bool gamescene: Init () {If (! Layer: Init () // initialize the parent class return false; // obtain the screen size = Director: getinstance ()-> getvisiblesize (); // auto size = Director: getinstance ()-> getwinsize (); Return true;} void gamescene: Draw (Renderer * Renderer, const mat4 & transform, uint32_t flags) {_ customcommand. init (_ globalzorder); _ customcommand. func = cc_callback_0 (gamescene: ondraw, this, transform, flags); Renderer-> addcommand (& _ customcommand);} voi D gamescene: ondraw (const cocos2d: mat4 & transform, bool transformupdated) {// use stack cache Director * Director = Director: getinstance (); // ccassert (nullptr! = Director, "director is null when setting matrix stack"); Director-> pushmatrix (matrix_stack_type: matrix_stack_modelview); Director-> loadmatrix (matrix_stack_type: matrix_stack_modelview, transform ); check_gl_error_debug (); // draw the border drawprimitives: setdrawcolor4b (255,255,255,255); gllinewidth (10); vec2 vertices [] = {vec2 (100,100), vec2 (300,100 ), vec2 (300,300), vec2 (100,300)}; drawprimitives: drawpoly (vertices, 4, true); check_gl_error_debug (); // stops plotting and releases Director-> popmatrix (matrix_stack_type:: matrix_stack_modelview);} void gamescene: menucallback (ref * psender ){}
Cocos2d-x3.2 draw line