Jump to content

[SOLVED] Problems with BitmapData.drawSprite


Matoking
 Share

Recommended Posts

Hey, I'm trying to use BitmapData but I'm having some trouble with its drawSprite method.

var bitmapData = game.add.bitmapData(500, 500);var image = game.add.image(0, 0, 'blocks_top', 0);bitmapData.drawSprite(image, 25, 25);bitmapData.drawSprite(image, 50, 50);

In this example I'm trying to draw the same image to the BitmapData object two times. However, the image isn't being drawn to the specified coordinates, instead being drawn to the coordinates specified in the Image object.

 

Also, if I want to draw the same sprite multiple times to the same BitmapData, do I need to create a Image/Sprite for each copy of the same sprite, or do I need only one Image/Sprite for each individual sprite? I'm asking because I managed to get the drawSprite method working by changing the to-be-drawn sprite's position to the coordinates passed to the drawSprite method, although I'm not sure if this is the correct way to solve this issue. In this case only the latter drawn sprite was visible (the one drawn to 50,50).

 

EDIT:

Now that I think of it, I think the issue has to do with the BitmapData not being rendered for some reason.

 

EDIT 2:

Oh right, you need to pass the BitmapData as a texture to a Sprite before you can render it. :P

 

EDIT 3:

I've solved the issue. Turns out all game objects are added to the game world unless they are created through game.make instead of game.add.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...