Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / collision with sprites

Author
Message
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 6th Feb 2012 18:23
is it possible to change sprite collisions so that, say;

sprite1 moved into sprite 2, sprite 1 would go to a set possition

but if sprite2 moved into sprite 1, sprite 2 would go to a set possition

because the way im doing it (if getspritecolision (sprite1,sprite2)) will only move 1 sprite

kirtnicholls
Canadian Mark
12
Years of Service
User Offline
Joined: 28th Jan 2012
Location:
Posted: 6th Feb 2012 19:35
You could check the angles or directions of the sprites
so it would look something like this in psuedo code. I'm at work and can't write the actual code right now but let me know if this what you mean and if you need help

A1 = sprite1 angle
A2 = sprite2 angel
if getspritecolision (sprite1,sprite2)

if A1 = pointed at sprite2
move sprite1 to location
set sprite2 position = sprite2 position
Endif

if A2 = pointed at sprite1
move sprite2 to location
set sprite1 position = sprite1 position
EndIf
EndIf
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 6th Feb 2012 19:48
I was thinking like a sandwich the sprite that is on top is moved an th bottom left where it is but i would like it to work with any sprite on top... If you get me?

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 6th Feb 2012 23:02
I'm going to use a sandwich as an example because its easy to visualise.

Say I have a piece of bread on my table and I put cheese on it the cheese will then move because the bread was there first

But

If I have a piece of cheese on my table and I put bread on it the bread will then move because the cheese was there first

In terms of sprites could I do that?

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 6th Feb 2012 23:10
Setspritepossition (sprite1,30,30)
Setspritepossition (sprite2,50,50)

If getspritecollision (sprite1, sprite2)
   Setspritepossition (sprite1,0,0)
Endif

I'd like something like this but it would have more coding I just wanted to outline main areas. I'd like it so that when sprite1 hits sprite2 sprite1 moves 

But I'd also like it so if sprite2 his sprite1 sprite 2 is moved 


I'm sorry if I'm not explaining it very well if I'm not I'll make a slide show to illustrate what I'm trying to say

kirtnicholls
Canadian Mark
12
Years of Service
User Offline
Joined: 28th Jan 2012
Location:
Posted: 6th Feb 2012 23:45
I can't quite see what you mean but it seems to me that there is a condition involved with both sprites.

In your example the higher sprite moves

condition1 = if sprite1 is higher than sprite1 then move sprite1
or

condition1 = if sprite1 is lower than sprite2 then sprite2

Either way you should be able to determine which sprite to move if you have a clear condition to check whether it's motion based or location based. If you ask yourself why the sprite moves or doesn't
you should be able to determine the condition

In the sandwhich example one of the sprites is on the table and one is not
condition = is on table

I hope this helps but if not we can keep working at it
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 7th Feb 2012 21:30
yeah thats what i mean, the toop sprite is moved and the bottom sprite is left there, would that be easier to code for

kirtnicholls
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 7th Feb 2012 21:39
If your condition is purely based on which sprite is higher once collided, you could do something like this...


kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 7th Feb 2012 22:02


kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 7th Feb 2012 22:32
could i do it with.. say "if getspritedepth" ?

kirtnicholls
kirtn14
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location:
Posted: 7th Feb 2012 22:37
i changed it to this, woudl you say it is ok?



kirtnicholls
Canadian Mark
12
Years of Service
User Offline
Joined: 28th Jan 2012
Location:
Posted: 8th Feb 2012 00:01
getspritedepth is used like a Z axis, for example your background
is painted first then your sprites on top of that. If you had a sprite that you wanted to move behind another sprite it could use a lower depth. Now as far as the table and sandwhich are concerned if you were looking top down at the table then depth would be important.
In a side view it would not apply but the height Y axis would

Login to post a reply

Server time is: 2024-05-06 09:30:20
Your offset time is: 2024-05-06 09:30:20