I have a node called Move Area.
if i touch it i should calculate if the touch is left (behind), the sprite in the middle of the area, or right(in front) of it.
Just a simple move left or right touch control.( ← | ->)
The Problem is if i do this:
onTouchBegan(event){
let delta1 = event.touch.getLocationX();
..................
it will give me back the Screen or OpenGL position.
for the calculation i need the position in node level.
my brain is smoking…
can u give me any suggestions on how to solve it?
I checked your requirement again and I think, we can just
create two touch areas; one for “moving left” and another one for right.
—————-
If you must calculate, you can
transform world’s coordinate to local node’s coordinate (you must do more reading, there are many ways to do that. eg: by using convertToNodeSpace. Again, rotation, anchor point, scaling etc etc must put into consideration. )
WOW… OKAY…
First of all MUCH Thanks to you and especially to your words:
Again, rotation, anchor point, scaling etc etc must put into consideration.
I was reading a lot about this Topic in the Forum and in the Documentation.
But thats not very self complaining. The “etc etc” in your Answer have made me think
I had it allready like that… but my Problem was the camera zoom!
In my case it is on 0.6 static.
I forget that in the calculation before i compare the middle Sprite PositionX with the touch locationX… now it works like a charm!
Here is the corrected part in my code:
let middle = cc.find("Canvas").convertToNodeSpaceAR(cc.find("Canvas/Main_Camera/Move_Area/Middle").getPosition());
let fingerpos = cc.find("Canvas").convertToNodeSpaceAR(event.touch.getLocation());
this.fingerpos_x = fingerpos.x / 0.6;
if(middle.x < fingerpos_x){
//Move left
}
if(middle.x > fingerpos_x){
//Move right
}
I thought about scaling and everything but not the cam zoom…
finally after 5 days of searching and fiddling! Tonight I’m sure I can sleep well.