Jump to content

Can I add a sprite to a bitmapdata?


Kobaltic
 Share

Recommended Posts

Well can I? I am porting a raycast engine over. It works great but it currently loads an img in JS. I want to use a sprite instead so I can use phaser to do all the niffty stuff. I don't want to waste my time figuring it out if it isn't possible. Thanks.

Link to comment
Share on other sites

I think you need to be a bit clearer about what you're trying to do. As regarding the title of your post, yes, in 2.0.6 you can simply use BitmapData.draw to add a sprite, image or whatever to a BitmapData object, but I don't think this is quite what you want to do - as this kinda defeats most of the point of having a sprite. I guess you want to use Phaser's sprites to represent objects in the world, and make use of the scaling etc? If this is the case, you may have to rewrite the routine you're adapting a bit more.

Link to comment
Share on other sites

I am trying to port a JS engine over to Phaser. My idea is to use Phaser's functions instead. I want to handle collision in phaser. I think I need sprites to do that. So i am trying to render sprites and not images. Here is the working code (the texuresFiles gets loaded into the textures array):

texturesFiles: [            "img/bluestone.png",            "img/greystone.png",            "img/colorstone.png",            "img/eagle.png",            "img/mossy.png",            "img/purplestone.png",            "img/redbrick.png",            "img/wood.png"objects.context.drawImage(objects.textures[wall.textureIndex],                                               wall.textureX, offsetY, 1, constants.wallSize - offsetY * 2,                                              i, scanlineStartY, 1, scanlineEndY - scanlineStartY);

I am trying to do this (no errors but not working):

texutreArray = [stone,stone,stone,stone,stone,stone,stone,stone];var rect = new Phaser.Rectangle(wall.textureX, offsetY, 1, constants.wallSize - offsetY * 2);bmd.copyPixels(textureArray[wall.textureIndex],rect,i,scanlineStartY);

The stones are sprites. I used the same one for prototyping and kept the number the same as the original array.

Link to comment
Share on other sites

I don't see how this would work properly with Phaser's collision system, which checks for overlapping 2D collisions - not the pseudo-3D collisions you have in raycast engines. In fact, I don't think much at all is particularly well suited to a raycasting engine within Phaser.

 

I'm afraid I can't help much with your code either - copyPixels looks like it's getting the correct parameters and it's certainly copyPixels which you would use to do this kind of thing. If you've copied and pasted this directly from your code, you may not have noticed that textureArray is misspelt in the first line - that could be causing it to fail maybe?

Link to comment
Share on other sites

Yeah I had a typo. It didn't fix the problem. I am not really sure if I need phaser for this. It is nice for the canvas and controls but I don't think the collision would work as you stated.

 

I get this error but I think I am just going to go straight JS on the rest and keep what I already have done in phaser.

 

Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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