libGDX: one actor on another input - libgdx

I'm writing checkers and have two types of actors: checkers and squares. And have a listener that react if the square was touched. But this works only if the square is empty. If checker is placed on top I can't do anything. If there smth like "priority" of actor(?) or a method that could help?
Thx

Touches are processed in the opposite order that they are added to the Group. This is also the reverse of the order they are drawn, so if something is drawn on top of something, it will also have touch priority over what is behind it.
In this case, it sounds like you need to set all your checkers to not be touchable. actor.setTouchable(Touchable.disabled)

Related

Overwrite pixel in cocos2-d

I'm writing with cocos2d-x, and have a problem:
For example, there are two sprites: a human and his clothes. I use fade (cascade opacity) to make it disappear, but during this the user can see the parts of the human body which were supposed to be hidden by the clothes. How to avoid this? How can I use render for that? Is there a way to overwrite pixels when render in cocos or OpenGL? Can anyone give an example?
You can use CCClippingNode to do the job.
CCClippingNode::create(cocos2d::CCNode *mask) (2.x type)
CCClippingNode::setInverted(bool)
It is used to create a clipping region. And you can use it to cover the body. Add the body in the clippingNode by addChild and use cloth as mask.

AS3: How to make movieclip appear on middle of a separate mc container?

I've been searching and having trouble doing this the right way.So my player has 2 arms which are joined in one mc. Now I'm trying to make the body(which is doesn't belong on the container mc) go between them, so it's like R arm first then body then L arm. The 2 arms rotate on mouse direction, i don't want the body too. Any ideas what way I should go?
EDIT:
please see my sample image
The checked thing is the result I'm looking for. But since the 2 arms is combined on one MC, I can't make the body appear on the middle between the 2 arms.
You should change your nesting model like this:
And then store your arms in an Array or a Vector, and change every arm's rotation separately.
It's the only way

cocos2dx - sub layer that covers its parent partially keep capturing all touches

In my cocos2dx game, I have a CCLayer that contains another CCLayer. The sublayer just cover part of the container layer. I 'think' I achieve this through:
this->setContentSize( CCSizeMake( 100, 200 ) );
however, the sublayer always capture touches even though it is outside its size and position area... Is it common?
I can filter through the touches position by comparing it inside the ccTouch** functions, but I think it is a hack, what is the proper way to set the sublayer to properly cover just the partial area of its parent?
The only thing i can think of straight away is making this inner layer a CCNODE and also extent it with CCTouchDelegate.
Now with this, when u register with the TouchDispatcher, you make sure it doesn't Swallowtouches(the boolean value given as the last parameter)...
This way when you receive a touch ... just see if it is within the boundary of this inner layer of urs and if it is not, send let the parent class use this touch.
Hope this helps.

AS3: weird getBounds() result

EDIT2: It seems that the big numbers are created because the movieclip doesnt hold any bipmapdata, but Im yet not sure about it, but my real mistake was that I just forgot "this" infront of one "getBounds" ... project size was to big and I couldnt find the bug =)
EDIT: tried to use seperate containers, for the movieclips, and did all this in the root class ... everything worked fine, when I used seperate containers and attached everything to the charakter class it got screwd up again
OLD:
Hey I am making a game right now and I want to get the bounds of the charakter body.
To understand how I did set the whole thing up I explain the hirarchy.
The class of my flash document is "game.as". "game.as" adds a Child of the class Charakter
my Charakterclass has a Movieclip for every body part, for example the "head"
every bodypart has a movieclip which contains the picture of the bodypart, in this case "head".
When I now try to use the getBounds(head.mc) inside the "head" class I get really weird results. ussualy something around x=64001, y=64001, width = 0, height = 0;
I found a way how to solve this problem by simply using the getBounds(head.mc) function not inside the head, but inside the Charakter class .... but this is not what I actually want to do, I would like to use the getBounds(head.mc) function inside the head class.
Any ideas why the results are so weird or what I have to do? Im very thankfull for every opinion, because this doesnt seem logical to me xD
getBounds() is inaccurate. Please read the following posts to understand the issue.
getBounds "wrong" results (Source)
When getting bounds of an object relative to it's OWN coordinate system,
those values will NOT be scaled.
getBounds() returning incorrect height (Source)
From inside head_mc, try getBounds(this.parent); (you may want to test to see if the parent exists first) - this should give you the bounds of your head_mc as its container sees it, which I think is what you want, but called from inside head_mc, as you request.
bitmapdata is right, though - getBounds() can sometimes give some odd results. It looks to me like you might be asking the question before you add head_mc to the stage, and are therefore getting the undefined values for width/height/x/y.

How to create a custom GControl

I'm trying to create a gray "frame" (see pic below) around a google map, to try to convey the concept of an area of focus, as oppose to a point (which is usually represented with a marker). Note that this is not an overlay, that is, the gray "frame" should not move when you drag the map.
Edited: image link added
It appears that only option is to "subclass" GControl to create a custom control. I have 3 questions
1) First of all, is GControl subclassing the best course of action?
2) In my example, the canvas (div) where map renders can change its size (i.e is not fixed width). Do I have to delete and add custom control when canvas changes size? See docs http://code.google.com/apis/maps/documentation/controls.html#Custom_Controls on how to create a custom map control.
3) Now, how to do it. Naively, I thought I could create a table with 3 columns and 3 rows, and set display: none for the cell in the middle. But that doesn't work. I've also experimented with clipping, that didn't work either. My css skills are quite lacking, so there must be way to do this more elegantly than adding four rectangular gray divs. If I wanted to add an inner border, with divs, I would need to paint 8 then. In a nutshell, what's the best way to create a "hollow" rectangle?
Thanks
P.S. This is my first entry to StackOverflow. Just discovered it. It's impressive how well SO is put together.