Some questions about collideSprites...
-
This post is deleted! -
I did some more experimenting and it turns out that the c.resolution vectors are quite useful for implementing sprite bounce. I just normalized the vector and multiplied it with the desired velocity.
In my main loop I have two nestled for loops in order to monitor each possible collision with any two ships. So the collideSprite method is called 2450 times for each update(). For 50 ships this is pretty smooth, but if I increase the number of ships further, slowdown occurs... Kind of interesting.
Feel free to check out my little demo of 50 bouncing spaceships!
ID: NBYUXMND5C -
@DomDom said in Some questions about collideSprites...:
Collisions have 2 phases. Detection and Response. On first inspection, the collisionsprite function looks like it handles detection and provides the necessary info (in the form of the vectors you're talking about) to enable the programmer to implement the response as he sees fit. This would imply that you need to set the resultant velocities yourself.
Thanks, I gave it a try!
-
This post is deleted! -
@DomDom said in Some questions about collideSprites...:
@vinicity Hope it helped.
By the way, checking collisions between 50 ships would only need 1250 checks if each ship only tests for collisions with the ships that are after it in a list.
Eg. something like
for sA=0 to Len(shipslist)-1
for sB= sA+1 to Len(shipslist)
C= checkcollisions(sA,sB)
Repeat
RepeatSomething else that might speed things up is to do a simple proximity check before the collision check.
Great point! I did not think of that, but in my defence I was kind of tired last night when I did the programming. Thanks!
-
So I made a few changes and optimizations, and cleaned up the code. Fifty bouncing ships makes for a nice screensaver...
-
I just shared a new version of my 50 bouncing ships demo. Cleaned up the code, added some optimizations to make it run smoother. Also made sure that ships that disappears at one edge are moved over to the other.
ID: NBYUXMND5C
-
-
Awesome job @vinicity !
I'm glad to hear the info was helpful. Looking forward to seeing what you make in the future!
-
Thanks! I am actually turning this into a game. I'll keep you posted once I got something new to show...
-
@Dave said in Some questions about collideSprites...:
You've actually caught Fuze at a bad time with that particular function page. There are errors on that page which really hurt.
I'll post here what is going to be included in an upcoming update to the help. This is what collideSprites() does:
collideSprites()
Description
Determine if two sprites have collided and optionally resolve the effect of the collision on their movementSyntax
c = collideSprites( spriteA, spriteB ) c = collideSprites( spriteA, spriteB, resolve1, resolve2 )
Arguments
spriteA
Handle - Variable which stores the first sprite in the collisionspriteB
Handle - Variable which stores the second sprite in the collisionresolve1
Integer - True (1) if the first sprite can be moved by the collision, false (0) if notresolve2
Integer - True (1) if the second sprite can be moved by the collision, false (0) if notc
Array - List of structures detailing collision data. Properties listed belowc.exists
Integer - True (1) if collision occurred, false (0) if notc.a
Handle - Variable which stores the first sprite in the collisionc.b
Handle - Variable which stores the second sprite in the collisionc.resolution_a
Vector - How sprite A was pushed during the collision { x, y }c.resolution_b
Vector - How sprite B was pushed during the collision { x, y }It would be nice if the collideSprites() help page could be updated with the info above, since the info that is there now is not really helpful. I know you guys are super busy, but this is just a friendly reminder so you do not forget it!
-
@vinicity i only figured the sprite collision thing last week, before i was just using true/false didn't know you could link events triggers ect been a big 1 -UP for my code since
-
@waldron said in Some questions about collideSprites...:
@vinicity i only figured the sprite collision thing last week, before i was just using true/false didn't know you could link events triggers ect been a big 1 -UP for my code since
Link events triggers? That sounds interesting. Care to elaborate a bit?
-
@vinicity
collide1 = collidesprites(sprite.plr,sprite.boss)
collide2 = collidesprites(sprite.plr,sprite.door)
if collide1 or collide2 then
(stuff happens)
endif
you can also add in stuff like boss health and have triggers on his/her health level. then you got else statements ect.
i only figured this after playing Steve's Row ya boat :) cheers Steve
i can add to this later
-
in Fact il cover it in my next video tutorial, iv sorted the quality in my last test so youl be able to actually see the code :) il cover sprite collisions and triggers wrapped in a simple boss fight program. il aim for next week to make and release it
-
@waldron said in Some questions about collideSprites...:
@vinicity
collide1 = collidesprites(sprite.plr,sprite.boss)
collide2 = collidesprites(sprite.plr,sprite.boss)
if collide1 or collide2 then
(stuff happens)
endif
you can also add in stuff like boss health and have triggers on his/her health level. then you got else statements ect.
i only figured this after playing Steve's Row ya boat :) cheers Steve
But how does that even work? collide1 and collide2 are not booleans (or actually integers; I know Fuze does not have proper bools), but structs? How can you test a struct in an if clause just like that?
I would have thought you would need something like:
collide1 = collidesprites(sprite.plr,sprite.boss)
collide2 = collidesprites(sprite.plr,sprite.boss)
if collide1.exists or collide2.exists then
(stuff happens)
endif
-
@vinicity sorry the second collision is supposed to be sprite. plr , sprite.door)
-
then if collide1 then//it already reads the collision between sprites because of the collidesprites function, the collide1 is just calling it
im guessing if you don't call if it exists then its at its default ??
il have to check when im home but works -
Are you saying that once you have called collideSprites() once, you can then test the resulting struct multiple times, and that it will update depending on whether the collision has occurred or not? So the collideSprites() call does need to be inside the game loop?
I must test this tonight, but I think it sounds a bit strange...
-
@vinicity i have it in my main loop yes, il double check also when home but works. i use it to collect sprites move sprites all sorts