preface

The Entry Task 2 I just entered the company is to implement the novice guidance function of a match-3 game. Since I just got into contact with Egret framework and games for the first time, I am not familiar with Egret and business. I am not good at code writing, so please understand !!!!

The most complicated function of the new guide mask is to show some things and hide other parts. In Egret, a number of circular rectangles are used to join together the parts to be displayed. The core code is to use RenderTexture dynamic texture to draw the display object and its children into a texture. Generally speaking, it is a screenshot operation, which saves the current picture and presents it as a screenshot.

/ / create a container, but the water in the container with other vector, text, bitmaps const container: egret, DisplayObjectContainer = new egret, DisplayObjectContainer (); Const egret.renderTexture = new Egret.renderTexture (); renderTexture.drawToTexture(container); Const Egret. Bitmap = new Egret. Bitmap(renderTexture); this.addChild(blendBitmap);Copy the code

code

The core of the implementation of novice guidance is to achieve the anti mask function, as follows:

// blendShape The blocked part. Static shadeFunc(blendShape: Egret. DisplayObject, Target: Egret. DisplayObject) {const Container: egret.DisplayObjectContainer = new egret.DisplayObjectContainer(); container.addChild(blendShape); container.addChild(target); target.blendMode = egret.BlendMode.ERASE; const renderTexture: egret.RenderTexture = new egret.RenderTexture(); renderTexture.drawToTexture(container); const blendBitmap = new egret.Bitmap(renderTexture); blendBitmap.touchEnabled = true; // Allow to click blendBitmap.pixelHitTest = true; // Whether to enable precise pixel collision. Set to true and the transparent region of the display object itself will be able to be penetrated. return blendBitmap }Copy the code

[Note] : It is important to note that if you want to click, you need to listen to the event to operate

conclusion

For programmers who are new to Egret framework, you can read more Egret official documents and write a small demo to learn, so that you can get started quickly.