Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Howto loose focus

DouweDabbe
Guest
Quote
2022-01-01 19:53:51

I got a 2d-overlay with a click event that works properly, it initiates a dragging function.

but now i want it to loose focus & stop dragging when my mouse leaves the 2d-overlay surface until it got clicked again.

how do i do that ??


just_in_case
Moderator
Quote
2022-01-02 06:12:25

You can simply check if the mouse is inside the overlay position or not by getting screen resolution and mouse position and overlay position and scale and then comparing them. You can use my code below if you want, just insert your dragging function, and your overlay node wherever necessary. I could have made it easy for you by creating a simple variable for overlay nodes and then inserting them everywhere but I want you to do some stuff on your own as well. so just replace the bold text along with your own preferences.


var scrWidth = ccbGetScreenWidth(); // screen width for calculating percentage
var scrHeight = ccbGetScreenHeight(); // screen height for calculating percentage
var mouseX = ccbGetMousePosX(); // getting mouseX pos in pixels
var mouseY = ccbGetMousePosY(); // getting mouseY pos in pixels
var posType = ccbGetSceneNodeProperty("your OIverlay","Position Mode"); // position mode of the overlay realtive/absolute
if(posType == "relative (percent)")
{
var overlayPosX = ccbGetSceneNodeProperty("your Overlay","Pos X (percent)");
var overlayPosY = ccbGetSceneNodeProperty("your Overlay","Pos Y (percent)");
var overlayScaleX = ccbGetSceneNodeProperty("your Overlay","Width (percent)");
var overlayScaleY = ccbGetSceneNodeProperty("your Overlay","Height (percent)");
var overlayPosX = (overlayPosX * scrWidth)/100; //getting pixels value instead of percentage
var overlayPosY = (overlayPosY * scrHeight)/100; //getting pixels value instead of percentage
var overlayScaleX = (overlayScaleX * scrWidth)/100; //getting pixels value instead of percentage
var overlayScaleY = (overlayScaleY * scrHeight)/100; //getting pixels value instead of percentage

}
else
if(posType == "absolute (pixels)")
{
var overlayPosX = ccbGetSceneNodeProperty("your Overlay","Pos X (pixels)");
var overlayPosY = ccbGetSceneNodeProperty("your Overlay","Pos Y (pixels)");
var overlayScaleX = ccbGetSceneNodeProperty("your Overlay","Width (pixels)");
var overlayScaleY = ccbGetSceneNodeProperty("your Overlay","Height (pixels)");
}
//check if cursor is over the overlay
if( mouseX >= overlayPosX && mouseX <= overlayPosX+overlayScaleX && mouseY >= overlayPosY && mouseY <= overlayPosY+overlayScaleY)
{
Dragging function here()
}
else // stop the execution of above code
{
Stop Dragging function here()
}


hope this helps


DouweDabbe
Guest
Quote
2022-01-02 22:10:50

I looked a bit better in the manual after your nice and elaborate answer, Thank You for that. !!!

and found these event type function handlers ?
(not shure about correct terminology)

myaction.prototype.execute = function() {}
myaction.prototype.onAnimate = function() {}
myaction.prototype.onKeyEvent = function() {}
myaction.prototype.onMouseEvent = function() {}


so I will need a mouseNOTover type of event handler
so will work out this with you kindly provided snippet.with :
myaction.prototype.onMouseEvent = function() {}

but it surprises me there is not more of these event handler
functions.
mouse over or not over must be there in the sdk else how would the out of the box color animation function work ?
this SDK solution would be much faster also, as being implemented in C.


DouweDabbe
Guest
Quote
2022-01-02 22:56:39

Actually this will also not work for android ,
its intended platform as there is no mouse but
only touch events and the manual says nothing how to handle that ... hmmm


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "In?ernational" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact