Problem with "bitmap.drawText"

● ARCHIVED · READ-ONLY
Started by King Gerar 3 posts View original ↗
  1. Hi, everybody!

    I'm creating the my project's menu, but came across with a problem. I did this code:


    this.menuHeaderImg = new Sprite();
    this.menuHeaderImg.bitmap = ImageManager.loadPicture("System - MenuHeader");
    this.menuHeaderImg.anchor.x = 0.5;
    this.addChild(this.menuHeaderImg);
    this.menuHeaderImg.bitmap.drawText("Menu", 0, 10, 136, 20, 'center');


    8L0dkrw.png


    Worked perfectly, like the image shows. But, when I tried do the same code to show other image...


    this.sceneHeaderImg = new Sprite();
    this.sceneHeaderImg.bitmap = ImageManager.loadPicture("System - MenuHeader");
    this.sceneHeaderImg.anchor.x = 0.5;
    this.addChild(this.sceneHeaderImg);
    this.sceneHeaderImg.bitmap.drawText("Status", 0, 10, 136, 20, 'center');


    3mvyp6b.png

    The new text is drawed over previous, in both images. Someone knows why? :/
  2. The loadPicture() retrieve the same bitmap from the cache. The best solution is to not draw on the Image bitmap, but instead, create a new bitmap, use blt to draw the picture on this bitmap, and draw the text on it.


    By retrieving the same bitmap, the text drawn on it is still there.


    Something like this:


    var bw = width;
    var bh = height;
    var bitmap = ImageManager.loadPicture("System - MenuHeader");

    this.sceneHeaderImg = new Sprite();
    this.sceneHeaderImg.bitmap = new Bitmap(bw, bh)
    this.sceneHeaderImg.anchor.x = 0.5;
    this.addChild(this.sceneHeaderImg);
    this.sceneHeaderImg.bitmap.blt(bitmap, 0, 0, bw, bh, 0, 0);
    this.sceneHeaderImg.bitmap.drawText("Status", 0, 10, 136, 20, 'center');


    The values you should set the value of bw and bh with the values you want for the bitmap.
  3. Thanks, Victor. I understood.
    Therefore, there is a method to clean this cache for this image? For the program "forget" this drawText when I draw the image again.

    Because, I'll try use one image for main menu and other for the scenes. When the player cancel a scene, I'll clear the cache for this image to it be without alterations when call other scene.