if(CGRectIntersectsRect(m_Heart, m_sBirdSprite.boundingBox)){
m_sHeart[i].visible=FALSE;
m_fTime += 1;
}
This is my code, and the problem is that i want to add only one value in m_fTime variable, but it is continuously adding +1 in m_fTime varible because it is in process to be intersecting, now is there any way to add only 1 value in it when it intersects?
You can use BOOL porperty
if(CGRectIntersectsRect(m_Heart, m_sBirdSprite.boundingBox) && [m_sHeart[i] isVisible]){
m_sHeart[i].visible=FALSE;
m_fTime += 1;
}
thanks for your kind answer #Himanshu Joshi its correct in terms of logic, but bit incorrect in terms of syntax i did try the same, i am not pointing your syntax wrong, just giving the correct syntax for our new/beginner friends. and i am marking your question as right answer.
if(CGRectIntersectsRect(m_sHearts, m_sBirdSprite.boundingBox) && m_sHeart[i].visible==TRUE){
m_sHeart[i].visible=FALSE;
m_fTime += 1;
}
In expert programming a simple way to use Boolean flags.
Same here you can implement the Boolean flags in your problem,
if(CGRectIntersectsRect(m_Heart, m_sBirdSprite.boundingBox) && [m_sHeart[i] isVisible]){
m_sHeart[i].visible=true;
m_fTime += 1;
}
Related
I'm writing some test helper functions to make the output more sensible:
bool tstEq(first, second) {
if(first == second)
return true;
else {
println("<first> was not equal to <second>");
return false;
}
}
Is it possible to do something like this?
bool ===(first, second) = tstEq(first, second);
usage:
test bool myTest() = 1 === 2
Which would result in something like:
rascal>:test
1 was not equal to 2
bool: false
A short answer: no. I fully agree that this can be convenient (but may also lead to less readable code).
Given the large list of topics we want to address first, it is unlike that such a feature will come to Rascal in the near future.
This is a question about the ++ operator. It is a question that doesn't solve a problem but I believe that it would be very informative to know the answer. So, while StackOverflow is a source of information, I would like to append the available knowledge here!
So, the problem:
int i = 0;
int getNextInt(){
return i++;
}
This is it. The question is how the ++ operator is implemented in the function call stack and where the increment actually happens when we call that function in our code.
I am really wondering a long time!
It happens after the function returns it's value. In this case, it returns 0 and then increments the variable, so the next time it will return 1
I have no idea what the compiler actually does with regard to the stack, but if it chose to, the compiler could easily rearrange it to this:
int getNextInt() {
int temp = i;
i++;
return temp;
}
i++ is the same as saying i = i+1
It is just a shorthand way of redefining the variable.
Ok so this is my scenario:
rascal>map[int, list[int]] g = ();
rascal>g += (1:[2]);
This will result in:
rascal>g[1];
list[int]: [2]
So far so good, but now I wanted to do this, but it didn't work:
rascal>g[1] += 3;
|stdin:///|(2,1,<1,2>,<1,3>): insert into collection not supported on value and int
So I can't directly use the value from g[1] and will have to use a temporary variable like this:
rascal>lst = g[1];
rascal>lst += 3;
rascal>g[1] = lst;
map[int, list[int]]: (1:[2,3])
But doing this everytime I want to extent my list is a drag!
Am I doing something wrong or would this be an awesome feature?
Richard
Good question! + on lists is concatenation not insert, so you could type the following to get the desired effect:
g[1] += [2];
I have some trouble compiling lodepng (http://lodev.org/lodepng/) for D into my project.
In Encode.d I have the following code, where the compiler does not expect the assert statements.
Removing this block solves the issue.
invariant
{
assert(compressionLevel >=0 && compressionLevel <= 9, "invalid zlib compression level");
assert(targetColorType == ColorType.Any ||
targetColorType == ColorType.RGB ||
targetColorType == ColorType.RGBA, "colortype is not supported");
}
In Decode.d I have even more trouble, with the error "no identifier for declarator inout(value)"
for the middle line in:
info.backgroundColor.length = chunk.data.length / 2;
foreach(index, inout value; info.backgroundColor)
value = chunk.data[index * 2];
Is there some trouble with old syntax here, and how do I fix it?
Is there some other way to create png images in D in a simple manner?
Not sure about the invariant problem, but the second problem should be solved by replacing the "inout" with "ref" (D2 syntax change).
I gave up on lodepng, and used the code on
http://www.dsource.org/projects/plot2kill/browser/trunk/png.d
which works after some minor changes.
I'm trying to get Velocity to output the following Javascript code:
if ((whichOne+1) <= numCallouts ) {
whichOne = whichOne + 1; } else {
whichOne = 1;
}
Whenever I try to get Velocity to print a > or a <, it represents it as a & gt; or & lt;, which doesn't help me since I'm trying to get it to produce Javascript. I've tried:
#set ( $gt = ">" )
But even that ends up as a & gt;
Thanks in advance.
It is not a default behavior, the only reason I can think of why this is happening is if you have event ReferenceInsertionEventHandler configured with EscapeHtmlReference either in your velocity.config or in the Velocity initialization code.
Here is more info about events
I've had the same issue with Velocity - however, the problem is that I was using Velocity as an third party embedded language, and didn't have access to change the Velocity settings.
Unfortunately the only solution I was able to find was to rewrite the code without using greater than/less than explicitly, which admittedly is awful, but it's all about getting it to work...
Here is an example workaround for conditionals where you are trying to see if one number is larger than another:
if (n1 > n2) //Doesn't work because velocity turns this into if (n1 > n2)
if (n1 != n2)
{
diff = n1 - n2;
abs = abs(n1 - n2);
if (diff / abs == 1) //Greater than
else //if == -1 then less than
}
else //Equal
Maybe you are able to use the alternate symbols as described here :
http://velocity.apache.org/engine/devel/vtl-reference-guide.html#aifelseifelse_-_Output_conditional_on_truth_of_statements
So try to use if (n1 gt n2).