Cocoscreator Coordinate code

Source: Internet
Author: User
Update:function (DT) {
Get the coordinates of the monsters
var sp = This.guaiwu.convertToWorldSpaceAR (This.guaiwu.getPosition ())
Get the coordinates of the turret
var pos = This.node.convertToWorldSpaceAR (This.node.getPosition ())
Cc.log (POS,SP)
Calculate the coordinate difference between a monster and a turret
var truepos=cc.p (SP.X-POS.X,SP.Y-POS.Y)
Convert their coordinate differences to radians
var angle=cc.panglesigned (TRUEPOS,CC.P (0,1));
Convert their radians to angles.
var angledegrees=cc.radianstodegrees (angle);
Each frame of the turret is angled toward the coordinates of the monster.
This.node.runAction (Cc.rotateto (dt,angledegrees))
var PO1 = this.paota.getPosition ()

if (0) {
Local coordinate transformation
var po2 = This.canvas.convertToNodeSpaceAR (Touch.getlocation ())
Cc.log (po1.x,po1.y, ' | ', po2.x, PO2.Y)
}else{
Global Coordinate transformation
PO1 = This.bg.convertToWorldSpaceAR (PO1)
PO1 = Cc.psub (Touch.getlocation (), PO1)
}
var at = cc.radianstodegrees (cc.panglesigned (PO1, CC.P (0,1)))
This.hand.rotation = at

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.