Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
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? |
||||
|
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... |
||||
|
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? |
||||
|
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
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. |
||||
|
YEEEEEEES!!! Works like a charm. Thanks for the help just_in_case |
|