Sign in to follow this  
Followers 0
PhasedEvolution

Phaser destroy bitmap (1.3)

13 posts in this topic

Hello. I have made previous threads about this specific issue but couldn't get my problem solved.

This time I made a codepen with my code which might make helping easier: https://codepen.io/PhasedEvolution/pen/mAaNkp?editors=1010

I want to make something similar to this: http://codepen.io/photonstorm/pen/ogZJPP?editors=001

However I am not being able to destroy the bmd I created and I don't know why... Can someone look into this and help me out?

Cheers

The_dude8080 likes this

Share this post


Link to post
Share on other sites

Did you forget 

wall_bmd.update();

?

Quote

If you have drawn anything to the BitmapData since it was created you must call BitmapData.update to refresh the array buffer, otherwise this may return out of date color values, or worse - throw a run-time error as it tries to access an array element that doesn't exist.

 

Share this post


Link to post
Share on other sites

Works for me.
Add it after

wall_bmd.ctx.fill();

 

Logging when hitting the wall gives me:

pixel? Object {r: 0, g: 0, b: 0, a: 1, h: 0…}
pixel? Object {r: 255, g: 160, b: 122, a: 255, h: 0…}

 

if(collision_pixel.a > 255)

is not going to work, 255 is max.
 

PhasedEvolution likes this

Share this post


Link to post
Share on other sites

@Milton Well it really works nice :P However when I change my code to this : https://codepen.io/PhasedEvolution/pen/mAaNkp?editors=1011 it doesn't work anymore.

I have tryed everything but I don't know why it doesn't work. The code I showed before was the simplified version of my actual code but I guess the problem wasn't there. It must be something related to the way I am "Pooling" my bullets (that is also making the game extremelly slow) I need a better way to do it. I am not sure if I can use phaser already made collision/overlap functions for this... But the biggest problem is really that. Why the bmd is not getting destroyed

 

Share this post


Link to post
Share on other sites

This sort of works:

if(get_collision_pixel.a == 255) { 
  bomb.x = 0; // or actually remove bomb
  //wall_bmd.blendDestinationOut();
  //wall_bmd.ctx.rect(bomb_x, bomb_y, 30,30);
  wall_bmd.circle(bomb_x, bomb_y, 10, 'rgba(0, 0, 0, 254');
  //wall_bmd.blendReset();
  wall_bmd.dirty = true;
  wall_bmd.update();     
}

The 'dirty' flag is the key I think...
Not sure how the other example triggers it...

PhasedEvolution likes this

Share this post


Link to post
Share on other sites
10 hours ago, Milton said:

This sort of works:


if(get_collision_pixel.a == 255) { 
  bomb.x = 0; // or actually remove bomb
  //wall_bmd.blendDestinationOut();
  //wall_bmd.ctx.rect(bomb_x, bomb_y, 30,30);
  wall_bmd.circle(bomb_x, bomb_y, 10, 'rgba(0, 0, 0, 254');
  //wall_bmd.blendReset();
  wall_bmd.dirty = true;
  wall_bmd.update();     
}

The 'dirty' flag is the key I think...
Not sure how the other example triggers it...

I will try to figure that out. You were a great help once again @Milton Thanks

Share this post


Link to post
Share on other sites

Hi Phased.

I really like your questions, you are on the right track :)
My advice to you would be, switch to Haxe/OpenFL.
I know it's quite an investment, but switching to a statically typed language is worth it...
You get your errors before you run, that'll help you a lot ;)

Share this post


Link to post
Share on other sites

@Milton thanks :) 

I did a brief search and OpenFL seems quite pleasent; will need to get used to that type of language though. But people seem to like it a lot :p. And I suppose that, as you said, it does bring advantages.

As for the community, tutorials, is it good?

 

Share this post


Link to post
Share on other sites

http://haxecoder.com/ is excellent, but I think it needs some older libraries. If you can install openfl 3.6.0 and lime 2.9.0 you should be good to go ( You can set versions with haxelib set).

Haxe/OpenFL is almost the same as Phaser. The same Flash people are involved. It's mostly based on Flixel. You could try HaxeFlixel to get started, that should be very familiar.

Share this post


Link to post
Share on other sites
47 minutes ago, Milton said:

http://haxecoder.com/ is excellent, but I think it needs some older libraries. If you can install openfl 3.6.0 and lime 2.9.0 you should be good to go ( You can set versions with haxelib set).

Haxe/OpenFL is almost the same as Phaser. The same Flash people are involved. It's mostly based on Flixel. You could try HaxeFlixel to get started, that should be very familiar.

Oh nice. I just got a little confused over all the concepts (Haxe, OpenFL, HaxeFlixel). What I understood from searching was something like this: Haxe is a programming language that shares similarities with C# ,for example. OpenFL was built on haxe and has something to do with compiling flash to multiple platforms? HaxeFlixel was built based on OpenFL and it is focused on game development? You said I could use HaxeFlixel to get started. Does that bring limitations in comparison to just use Haxe/OpenFL for instance? I am not sure if this question makes any sense though...

Share this post


Link to post
Share on other sites

I wouldn't compare Haxe to C#. C# is like Java. I am a certified (Oracle) Java developer, and I hate it. Haxe, like JavaScript and Flash (ActionScript), is based on (similar to) ECMAScript.
The fun thing about Haxe is that it compiles to most any other language. You don't have to worry about that though. Write once, and then just say, I'd like to have this in Javascript, C, PHP, Java, whatever...

OpenFL justs gives you a very Flash like API, Displaylists, Sprites etc.
HaxeFlixel is like Phaser, a pretty complete game engine.

 

PhasedEvolution likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.