GMS 2 A question about programming an object.

A

Aron Lehrmann

Guest
Hey guys.
I need your help. I am still new in programming things. I use the gamemaker Studio 2. In my game there are the following objects: a ball and different platforms. The ball is allowed to roll only on the platforms. If the ball falls off the platform the ball should be destroyed. How can I program into the object "ball" that it will be destroyed as soon as it no longer touches an object?
 
X

Xinera

Guest
To do this you can use the place_meeting function.

There are a lot of different ways to approach this problem depending on if you want the ball to destroyed as soon as it's no longer touching the platforms or if you want it to get destroyed when it falls off the platform.

For the first alternative you can use this in the step event of the ball:
if (!place_meeting(x,y+1,<name of the platform object>))
{
instance_destroy();
}
When the platform is not 1 pixel under the ball then the ball will be destroyed.

For the second alternative you can make the ball get destroyed as soon as it leaves the room in the step event of the ball.
if y >= room_height + sprite_height/2
{
instance_destroy();
}
So as soon as the balls y coordinate is equal to the rooms height + the height of the objects sprite/2 since the origin point is in the middle of the ball it will get destroyed.

This is how i would have approached the problem but i'm sure there are a lot of other ways to approach this. I'm also pretty new to gamemaker so hopefully this should work :D
 
A

Aron Lehrmann

Guest
[QUOTE = "Xinera, Beitrag: 349229, Mitglied: 36753"] Dazu können Sie die Funktion place_meeting verwenden.

Es gibt viele verschiedene Möglichkeiten, dieses Problem anzugehen, je nachdem, ob der Ball zerstört werden soll, sobald er die Plattformen nicht mehr berührt, oder ob er zerstört werden soll, wenn er von der Plattform fällt.

Für die erste Alternative können Sie dies im Schrittereignis des Balls verwenden:
if (! place_meeting (x, y + 1, <Name des Plattformobjekts>))
{
instance_destroy ();
}
Wenn sich die Plattform nicht 1 Pixel unter dem Ball befindet, wird der Ball zerstört.

Für die zweite Alternative können Sie den Ball zerstören lassen, sobald er den Raum im Schrittereignis des Balls verlässt.
wenn y> = Raumhöhe + Spritehöhe / 2
{
instance_destroy ();
}
Sobald die y-Koordinate der Bälle der Raumhöhe + der Höhe des Objekts Sprite / 2 entspricht, da sich der Ursprungspunkt in der Mitte des Balls befindet, wird er zerstört.

So wäre ich an das Problem herangegangen, aber ich bin mir sicher, dass es viele andere Wege gibt, dieses Problem anzugehen. Ich bin auch ziemlich neu für Gamemaker, also hoffentlich sollte das funktionieren : D[/ QUOTE]

Vielen Dank für die schnelle und ausführliche Antwort. Geht leider nicht. Wissen Sie, was das Problem ist?
 
A

Aron Lehrmann

Guest
[QUOTE = "Aron Lehrmann, Posten: 349243, Mitglied: 36774"] [QUOTE = "Xinera, Beitrag: 349229, Mitglied: 36753"] Dazu können Sie die Funktion place_meeting verwenden.

Es gibt viele verschiedene Möglichkeiten, dieses Problem anzugehen, wenn der Ball nicht mehr geht, oder wenn er von der Plattform fällt.

Für die erste Alternative können Sie im Schrittereignis des Balls
if (! place_meeting (x, y + 1, <Name des Plattformobjekts>))
{
instance_destroy ();
}
Wenn sich die Plattform nicht befindet, wird der Ball zerstört.

Für die zweite Alternative können Sie den Ball zerstören lassen.
wenn y> = Raumhöhe + Spritehöhe / 2
{
instance_destroy ();
}
Sobald die y-Koordinate der Bälle der Raumhöhe des Objekts gefallen ist, wird der Ursprungspunkt in der Mitte des Balls liegen, wird er zerstört.

So wäre ich an das Problem herangegangen, aber es gibt viele Wege, dieses Problem anzugehen. Ich bin auch ziemlich neu für Gamemaker, hoffentlich sollte das funktionieren: D [/ QUOTE]

Thank you for the quick and detailed answer. Unfortunately it does not work. Do you know what the problem is?
 

Attachments

Death

Member
The problem seems to be the posting in German, not English ;)
Just kidding, anyway look at the space after the !...
 

TheouAegis

Member
Um, <boden0,boden1,boden2> is not valid syntax. Assign each of those a parent object and check for the parent object.

Edit: When the other guy said <name of the platform object> he didn't mean to actually write the brackets.

if !place_meeting(x, y+1, boden0)
 

TheouAegis

Member
The problem seems to be the posting in German, not English ;)
Just kidding, anyway look at the space after the !...
GM doesn't care about the space there. It does when calling scripts/functions, but in most other places it doesn't. You can even leave spaces out of a lot of places people typically put spaces as long as it's still legible.
Code:
if!x{while!x++++x}
Code:
while!(x)++x;
Brackets are needed for legibility for GM in these cases.
 

Joe Ellis

Member
This thread was really cute and nice until people with profile pictures appeared, it seemed really genuine and just wanting to help each other, and people with profile pics have an online ego, (sorry to most of the gmc, its not a hateful attack but I think it opens your eyes into just helping each other, I'm just saying that egos sometimes get in the way, and distort\make things worst than they are
 
A

Aron Lehrmann

Guest
Um, <boden0,boden1,boden2> is not valid syntax. Assign each of those a parent object and check for the parent object.

Edit: When the other guy said <name of the platform object> he didn't mean to actually write the brackets.

if !place_meeting(x, y+1, boden0)
Thank you it works
 

Death

Member
This thread was really cute and nice until people with profile pictures appeared, it seemed really genuine and just wanting to help each other, and people with profile pics have an online ego, (sorry to most of the gmc, its not a hateful attack but I think it opens your eyes into just helping each other, I'm just saying that egos sometimes get in the way, and distort\make things worst than they are
Hmm, bruised ego from the profile with the W pic? ;)
You DO know that this is an ENGLISH ONLY forum, right?
 
This thread was really cute and nice until people with profile pictures appeared, it seemed really genuine and just wanting to help each other, and people with profile pics have an online ego, (sorry to most of the gmc, its not a hateful attack but I think it opens your eyes into just helping each other, I'm just saying that egos sometimes get in the way, and distort\make things worst than they are
My ego says thankyou for your input, but it doesn't quite understand where you are coming from. There was only one reply to the OP that didn't have a profile picture, the rest were the OP.

My ego also says why are you implying that once people with profile pictures showed up, did the interaction not seem genuine.

Finally, my ego observes, as did @Death, that you also have a profile picture, so perhaps you are being tongue-in-cheek, but it didn't occur that way to me.
 
Also, if you think anonymity (i.e. not having an easily recognisable presence, otherwise known as a display pic) on the internet INCREASES positive interactions, I'm not sure what parallel universe you are using the internet in (or perhaps you think there's some bizarre correlation where a display pic decreases positivity or something like that?)
 

Joe Ellis

Member
It wasn't to do with actually having a profile pic, or that having a profile pic is bad or causes anything negative, or directed at anyone in this thread, it was just something I've noticed that happens
 
Top