Jump to content


Photo

image_speed?


  • Please log in to reply
9 replies to this topic

#1 GrayKnight2k

GrayKnight2k

    GMC Member

  • GMC Member
  • 46 posts

Posted 24 April 2012 - 01:22 AM

I have two objects. One is obj_ballbounce and the other is obj_balljump. One object changes into the other depending on whether the ball is just bouncing in place or jumping left / right. If it is jumping, I want image_speed = 2, otherwise, image_speed = 1.

I've tried obj_balljump.image_speed = 2 in the create event and the step event of obj_balljump...but it changes the speed of both objects. How do I set image_speed specifically to obj_balljump so it doesn't change the image speed of obj_ballbounce?
  • 0

#2 The2Banned2One

The2Banned2One

    BANNED

  • GMC Member
  • 225 posts
  • Version:GM:Studio

Posted 24 April 2012 - 01:26 AM

Is one of the objects a parent of the other one?
  • 0

#3 GrayKnight2k

GrayKnight2k

    GMC Member

  • GMC Member
  • 46 posts

Posted 24 April 2012 - 01:30 AM

No
  • 0

#4 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 565 posts
  • Version:GM8.1

Posted 24 April 2012 - 01:34 AM

In the create event of each object you should just have to set image_speed to what ever you want.
so in the create event of obj_balljump, put:
image_speed = 2;

Thats it.

Edited by C_Pike, 24 April 2012 - 01:34 AM.

  • 0

#5 Cpt Chuckles

Cpt Chuckles

    GMC Member

  • GMC Member
  • 312 posts
  • Version:GM8.1

Posted 24 April 2012 - 01:34 AM

copy/paste Object Information in here for both objects
  • 0

#6 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 565 posts
  • Version:GM8.1

Posted 24 April 2012 - 01:40 AM

copy/paste Object Information in here for both objects


I think the problem is he is referencing the other object: obj_balljump.image_speed = 2
But seeing the code wont hurt.
  • 0

#7 GrayKnight2k

GrayKnight2k

    GMC Member

  • GMC Member
  • 46 posts

Posted 24 April 2012 - 01:43 AM

Thanks, everyone, for your fast replies and willingness to help.

I am embarassed by the solution, but I simply added "image_speed = 1" in the create event of obj_ballbounce.

I am puzzled why GM wouldn't assume a standard image speed. I needed to define it in the object since I changed the speed in the obj_balljump object...

EDIT: is it because when one object changes into another, the new object inherits certain characteristics of the former? This is a good lesson learned.

Edited by GrayKnight2k, 24 April 2012 - 02:08 AM.

  • 0

#8 C_Pike

C_Pike

    GMC Member

  • GMC Member
  • 565 posts
  • Version:GM8.1

Posted 24 April 2012 - 11:33 AM

EDIT: is it because when one object changes into another, the new object inherits certain characteristics of the former? This is a good lesson learned.


Only if the object is the parent of the other which is why The2Banned2One asked. When an object is created, it runs its own create event. You overrode the image_speed by referencing it with another obj_balljump.image_speed = 2 is looking at all instances of ball jump and making them = 2. image_speed = 2 is just setting the current object's image speed to 2.
GameMaker sets the image speed to something pretty quick by default, but you were overriding that.
----
Parents work like:

obj_ballParent:
<create event: image_speed = 2; health = 100; ball_blendColour = c_red;>

obj_ballBounce:
<parent = obj_ballParent>

obj_ballJump
<parent = obj_ballParent>
<create_event: call parent event; image_speed = 1>


All the balls have a blending colour of red, a health of 100, and all except obj ball bounce have an image speed of 2.
So... as you can see, the parent contains all the variables. obj_ballBounce has no variables of its own (its empty, not even a create event). It gets its variables from obj_ballParent.
obj_ballJump also gets its variables from obj_ballParent, but its image speed is different. obj_ballJump needs a create event, but it wants the variables from the parent so it calls the parent event before making its variable image_speed = 1.
If you don't call the parent event when creating a new event in an ancestor object, it will override the parent event completely.

Having parent objects is a good idea as it cuts down on the coding and debugging process considerably.

I hope this was helpful!

Edited by C_Pike, 24 April 2012 - 11:34 AM.

  • 0

#9 GrayKnight2k

GrayKnight2k

    GMC Member

  • GMC Member
  • 46 posts

Posted 25 April 2012 - 01:26 AM

This is extremely helpful! Thank you
  • 0

#10 ParodyKnaveBob

ParodyKnaveBob

    theUndiscovered

  • GMC Member
  • 990 posts
  • Version:GM:Studio

Posted 25 April 2012 - 03:20 AM

EDIT: is it because when one object changes into another, the new object inherits certain characteristics of the former? This is a good lesson learned.

Yep. When you use instance_change() (or :GM025:), your instance keeps all the former's variables! ...And you could've tested this yourself instead of asking; if nothing else, set some variables in an object, change the instance to another object, and watch in debug mode while that instance keeps all its former variables in place.

I hope this helps,
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users