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 Studio Chat / What Sprite Collided

Author
Message
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 15th Nov 2020 21:29
Disclaimer: I am very new to AppGameKit

When working with Sprite that Move around the screen (Either by Mouse, Keyboard, Joystick, etc...) is there a function that tells me the Sprite IDs of the sprites that most recently collided? I know I can feed "GetSpriteCollision" two Sprite IDs to see if they collide, but I am not finding a function that simply reports on the last collision of two sprites.
TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 17th Nov 2020 19:30
getspritehit(x,y)
getspritehitcatagory()

return sprite id

use app game kit documentation website for more information
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 17th Nov 2020 20:22
Interesting use case, and thank you TamBam.

Let me see if I can frame this better than my original post and see if I understand what you are suggesting.

In this example, let us say we have a square block that can be moved around. There is a field of other Sprites on the screen that are stationary and cannot be moved.

Using the mouse (or touch surface) we can move the box through the field of stationary objects, so the box is already attached to the mouse pointer or touch.

This was the context that was missing from my initial question. GetSpriteHit, will return the ID of the Sprite that is actively being moved around (which is fine). With the number of views to this thread and lack of replies I suspect there is no function that triggers when items collide (or contact, I see the term is confusingly interchangeable). I can "Check" to see if Sprites collide by supplying their IDs. I Can check to see what Sprite is actively being touched with the mouse or touch event (and even limit that with GetSpriteHitCategory), but there is no built in function that stores the ID or IDs of any sprite involved in a recent collision (natively).

Ultimately I wrote my own function that loops through the array of all available stationary sprites and checks them against my sprite that is in movement, and returns the ID of the closest sprite using GetSpriteDistance() as well as the last collision GetSpriteCollision().

I could be wrong as I have not had a chance to read through the documentation at length, but the above method is likely the only solution (Looping through available Sprites).
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 17th Nov 2020 22:00
you're talking about physics and so need to move your sprites with the physics commands to use them but those can return contact when they collide
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 17th Nov 2020 22:51
Thanks SmallG, I will work through that tutorial this evening and see if it provides the functionality I am looking for. Expect a reply with my findings/experience : )
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 18th Nov 2020 00:46 Edited at: 18th Nov 2020 00:47
You simply move the Sprite under the mouse and then check for a collision and then move it back it'll never be visible because it happens long before us a update or sink happens

Movemousesprite +1000 getspritehit(mouseousex,mousey) movemousesprite-10000

DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 18th Nov 2020 01:23
SmallG: I watched the tutorial video and learned a few new things that I had not considered before. It is a great demonstration for Physics Sprites that are affected by gravity. My thought exercise involves 100% static sprites (for now), it has no real application other than learning more about how to use the scene editor and what is available in the programming language itself. I will post a video of what I have been working on soon, that should better illustrate my questions and purpose. I Do appreciate the video link and plan on watching the rest of that series.

Smerf: Your suggestion while very simple, is also rather clever / quick to implement. I think I understand what you are saying. It is easy enough to test the position of (anything) by choosing a target location, setting your sprite, checking the collision status, returning the sprite to the original location (executing and logical code) and then proceeding to the Sync() directive. I have not applied that concept yet in my program, but will and then follow up here.
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 18th Nov 2020 02:24 Edited at: 18th Nov 2020 02:31
I Put this working example together that illustrates using a pointer (mouse or touch) to set the position of a sprite on the screen. There are 4 other obstacles in the scene that I do not want the interactive sprite to move through. If the moveable sprite comes into contact with the other solid objects it stops moving in that X or Y direction. The pointer continues to control the X (If Y is restricted) or the Y (if X is restricted). I do have physics turned ON for all sprites, but keep them all set to static. I am curious to see what will happen if I apply force to one of the "wall" objects, either have it move or spin, will it pull the small box sprite away from the pointer position? Or will the sprite that is following the pointer around, stay with the pointer.

Granted none of this is practical really and I am mostly interested in the active (built in) physics, as well as any user generated control or interruption that can take place when I write code to grab and move objects (sprites) around interactively with the mouse, touch or other method.

Mote to come and I do appreciate the suggestions and guidance from the more seasoned members of the forum.

(Apologies in advance if the uploaded video is only available as a link, I was unsure of had to embed)

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Nov 2020 03:07 Edited at: 18th Nov 2020 03:07
You cannot simply move a sprite when you use physics. You have to use forces and joints
If you want to manipulate a sprite using the mouse in physics you should use the Mouse Joint
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 18th Nov 2020 03:23
Smerf: lets hope so!

Blink0k: That is a good tip. I Will work with CreateMouseJoint() and see if I can accomplish the same effect.
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 18th Nov 2020 14:53
Blink0k: Ok So I followed that example and see how I may be able to use it to simplify my code! It is very useful. I need to find some time later tonight to play around with it a bit more, but overall I think this may be what I was looking for. Thank you very much for pointing me in that direction. (There may be a pun in there somewhere). Once I get it working the way I wanted, I can post a follow-up video and source code if others would find it helpful.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
DemonBoyXP
3
Years of Service
User Offline
Joined: 6th Nov 2020
Location:
Posted: 19th Nov 2020 12:12
Blink0k: I Will definitely look at those too and I did get farther along with the mouse joints. Should have something at some point

Login to post a reply

Server time is: 2024-03-28 12:13:25
Your offset time is: 2024-03-28 12:13:25