Hey everyone!
This will be my first post and I'm very excited about creating my own game. I have some previous JavaScript experience but it's been a while. Anyway, at the moment I'm trying to understand how functions work in C2 but i can't seem to get a grip on some things.
Below you will find an image of my current test. Basically what I'm trying to do is to have a toggle function. When an object is clicked, it will call a function which will fade in another object (an image, some text or whatever). If the object already is visible, i want it to fade out... easy right?
<img src="http://i.imgur.com/I5d7fu7.png" border="0" />
So my problem is this. I want to pass three values into the function, the target object, the fade in time and the fade out time. These should set the the target objects behavior fields to those values. So in order to get it to work i have been struggling to understand how the functions work in C2.
If i have a function object and set its name as fadeToggle, is this the same as:
function fadeToggle(targetObj, in, out)
{
// set fade in and out values
}
OR
var fadeToggle = function(targetObj, in, out)
{
// set fade in and out values
}
Aren't these then set in GLOBAL scope? What i want to do is have something similar to this:
var gameObject = {
fadeInTime: 0,
fadeOutTime: 0,
fadeToggle: function(targetObj, in, out) {
// set fade in and out values
}
};
Anyway, after trying for a while i can get an object to appear when i click a button and then disappear when i click it again, but not with proper fading. It fades in and out alright. But then when i click it again nothing happens. Both are set as "restart fade".