Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Changing texture with mouse clicks

poliginal
Registered User
Quote
2021-04-07 21:28:06

I got another question.

I have a "ccbDrawTextureRectangleWithAlpha" in my scene that is executed trough javascript.

I want to change between different textures when i hold down the mouse, and when i let go of the mouse.


Here is the code i am working on.

function onFrameDrawing()
{



var mouseX = ccbGetMousePosX();
var mouseY = ccbGetMousePosY();

ccbDrawTextureRectangleWithAlpha("glove.png", mouseX-100, mouseY-100, mouseX+100, mouseY+100);



}


ccbRegisterOnFrameEvent(onFrameDrawing);


How do i set up mouse events,if statements etc?


just_in_case
Moderator
Quote
2021-04-08 05:49:56

You can set this script to execute in the behavior "when a key is pressed do something" and can set mouse keys there. Or you can also register mouse events the same way you are using the on framevent...


poliginal
Registered User
Quote
2021-04-08 12:03:29

Thanks for your answer. I forgot to tell that i want the texture to always follow the mouse position (that is why i use the framevent).

I tried "when a key is pressed do something", and the texture changed but the previous still stayed on screen.

So how do i show the first texture, and then clear the texture from the screen and then show another one?


I don't know how to program mouse event.
Any chance you can help me a little bit with that?


just_in_case
Moderator
Quote
2021-04-08 13:29:11

there can be many ways of doing this. The simplest and easy one is to unregister your frameevent.

ccbUnregisterOnFrameEvent(func) 
you can use this command to unregister your previous function ( you can assign different names to your textures function and can then register and unregister them.

you can also use variables within your frameevent functions with if and else statements.
if you don't want to unregister frame events.

for example

var texture = ccbGetCopperCubeVariable("Texture");

if (texture == "glove")
{
ccbDrawTextureRectangleWithAlpha("glove.png", mouseX-100, mouseY-100, mouseX+100, mouseY+100);
}
else
if (texture == "hand")
{
ccbDrawTextureRectangleWithAlpha("hand.png", mouseX-100, mouseY-100, mouseX+100, mouseY+100);
}


you can use something like that, am not sure but this should work if you are planning to use this method then you need to set the variable on when a key is pressed do something, set or change a variable, in the above example I've used "Texture" as the variable name you can whatever you want. then can provide it a value like ( glove or hand ) or something else accordingly.

hope this helps.



poliginal
Registered User
Quote
2021-04-08 14:13:20

YEEEEEEES!!!
Works like a charm.
Thanks for the help just_in_case


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internati?nal" (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