Page 1 of 1

help with sprite collision

Posted: Sun May 01, 2016 5:56 pm
by sesco
I'm getting the error ' Sprite 0 is not on screen!' for this collision check below but I only defined Sprites 1,2, and 3 :?:

-----------------------------------------------------------------------
If Collision(#SPRITE, sprite1, sprite3) = True
DisplaySprite(2, 0, 0)
Else
DisplaySprite(3, 0, 0)
EndIf

Re: help with sprite collision

Posted: Sun May 01, 2016 7:40 pm
by fjudde
We need to see more of the code. Which values have you assigned to the variables sprite1 and sprite3? You need to give them the same number as the corresponding sprites

When I work with sprites I use constants with describing names instead of variables:

Code: Select all

@SPRITE 1, "I-PointBlack.png", {Transparency = #WHITE}
Const #Ipoint = 1
@SPRITE 2, "Sword32x20transWhite.png", {Transparency = #WHITE}
Const #Sword = 2
And then I use the constants throughout the program when referring to the sprites

Code: Select all

If Collision(#SPRITE, #Sword, #Ipoint) = True
    ...do stuff...
EndIf
Makes it easier to read your own code later on when sprite are described with names instead of numbers or digits.

Re: help with sprite collision

Posted: Mon May 02, 2016 5:25 pm
by fjudde
fjudde wrote: When I work with sprites I use constants with describing names instead of variables:

Code: Select all

@SPRITE 1, "I-PointBlack.png", {Transparency = #WHITE}
Const #Ipoint = 1
...
Well, this is even better, the constants first!

Code: Select all

Const #Ipoint = 1
@SPRITE #Ipoint, "I-PointBlack.png", {Transparency = #WHITE}
I should have done it this way earlier :roll: Well never too late to change.