how check overlapse not transparent fragment object in libgdx - libgdx

Libgdx.
I have 2 objects: Bucket and drop.
I use Sprite to manipulation on this objects.
How to check overlapse of non-transparent fragment of objects?

I really don't think that there is a function that could handle that.
I use to remove margin that represent the non-transparent of a sprite content
for example if the we put the size of the rectangle that represent the coins like this picture and we ignore the transparent part of the Sprite
good luck !

Related

Possible to mask an animated Movie Clip? Flash as3 cs4

I have a simple animation set up - A background I have painted in P/Shop and a Sheep.
The sheep is an animated movie clip - whose head turns and body moves.
What I need to happen is that when the sheep walks under a tree - he is in complete shadow - until he walks out from under the tree.
So far I managed to put the sheep under a shadow layer.. mask the shadow and use a rectangle which is aprox sheep size - it then moves along a tween teh same as the sheep.. It is quite clunky though and will take a fair amount of work reshape the mask shape each time to cover the exact sheep.. even then I won't be able to follow the animation exactly.
So, is there a way to have the animated sheep be a movie clip and a mask - so that he goes into full shadow everytime he passes under a tree.
Or is there another way to achieve this? Thx
The problem is cacheAsBitmap property,
you must assign maskclip and your maskedclip property to cacheAsBitmap = true
For example:
maskmc.cacheAsBitmap = true;
myMaskedClip.cacheAsBitmap = true;
myMaskedClip.mask = maskmc;
I added sample fla file that you can check it here : FLA
Can you put your sheep on a layer in between the shadow and the background? Probably not because you want the sheep in front of the tree -
Maybe you need to put a shadow element inside the sheep movie clip, and use a script to fade it in or out depending on hit test with the tree.
You could add a duplicate copy of the sheep to be used as a mask, although a shadow would probably need softer edges than this kind of mask will give you.

How to detect if there is a drawing/graphic drawn on a movie clip in AS3?

I am a newbie to AS3. I have a movie clip.I want to know if there is a drawing/graphic drawn over movie clip at all?
Simple, check the width and height of the MovieClip. Assuming you mean the MovieClip itself contains the drawing/graphic.
After seeing Fygo's comment
I did some testing and found out that the scale properties of the MovieClip will change depending on whether or not it has any graphics.
Meaning if you set the width and height to zero, the corresponding scaleX and scaleY will also be set to zero. So what you can do is check the scale AND the dimensions of the MovieClip. If both scales are 1:1 and both dimensions are 0:0, that means you didn't mess with the dimensions and it truly is graphic-less.
trace (awd.scaleX, awd.scaleY, awd.width, awd.height);
//If you get 1 1 0 0 as the output, the MovieClip is empty
Use readGraphicsData(). I assume that if it's empty it means there is nothing drawn there :)
It's not perfect though, read the reference
Maybe you just mean collision detection? To detect if two movieClips are touching...?
For that you need either:
HitTestObject - (checks if two objects touching by their box boundaries) - Link:
or HitTestPoint - (read description carefully) - Link:
A good tutorial explaining both methods is here: - Link:
example code:
if ( MC_one.hitTestObject(MC_two) )
{
trace("MovieClip One is touching/over MovieClip Two");
//add code needed to happen when touching/over. example below
//MC_two.gotoAndStop(2); //example tells touched MC_two to change frame to 2
}

Make bitmap partially invisible AS3

I am trying to make a object (movie clip containing textfields and bitmaps) and I need to make it partially transparent at times (like making half of it disappear). How is it possible?
// only things inside the rect will be visible
DisplayObject.scrollRect = new Rectangle(...);
A MovieClip is also a DisplayObject.

AS3 Custom HitTest

I am thinking of doing a platform game in flash. The approach towards level design I am thinking of is to have each level as an image with either a transparent or solid colour background.
Using regular hittest functions determines if one object has touched another object. In this case this will always return true.
My question is, I want a hitTest function to return true if the player character collides with any non transparent / solid colour on the level.
If I do have a transparent background I will probably have another image as a background that would move a little more than the level image to create a simple parallax effect. If I do this, the hitTest function would need to ignore the background image (I don't think this will be an issue, but still better to specify and be called an idiot than not).
This is an inefficiency method but its the simplest solution:
if (player.hitTestObject(platform) && platform.alpha == 1) {
trace("we landed!!!");
} else {
trace("we fell!!!");
}
Consider using the AS3 Collision Detection Kit as it can detect hits on colours.

as3 dynamic index change for added objects on stage

I have added some backgrounds on stage and then on top of that adding another background and all these are movieclips.
At some time i have to remove the backgrounds and then it should be added but here problem am facing is the background become coming front.
so is there any function like send to back or bring to frond based on the movie clip names.
You want to experiment with :
setChildIndex(object, z-value)
This set the depth of the object on the stage.
swapChildren (object1, object2)
This exchange the position of two objects on the stage.
setChildIndex
swapChildren
swapChildrenAt
addChildAt
Use addChildAt(index);
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#addChildAt()