Jump to content


Photo

Create_instance Help


  • Please log in to reply
3 replies to this topic

#1 Odb718

Odb718

    GMC Member

  • GMC Member
  • 207 posts

Posted 31 October 2008 - 09:17 AM

I'm trying to create an object with 1 of 2 sprites, a left or a right version, based off of an object that isn't moving.

I have a series of objects that represent 1 spear. The spear on the ground I pick up and hold, the spear that's thrown in the air, and the spear that sticks into the wall/objects.
I have it set up so that the spear turns with my character. If I face left the spear uses the left sprite, right gets the right sprite. The ground/held sprite and the in the air sprite all tell the next object what sprite to use.

Now my character can walk up to a spear in a wall and pull it out. The spear drops to the ground and then I can pick it up.
This is the code I use to pull the spear out.
if global.SpearInHand = 1 { exit; }   //checks to make sure you can only have 1 spear and not pull another spear out of the wall
if global.SpearInHand = 0						 
{
  if collision_rectangle(x-22,y-3,x+53,y+2,MyCharacter,1,1) >= 0   ///makes sure you're touching the spear
  { 
   instance_create(x,y,spear); instance_destroy(); exit; 
  }  
}
I know I can use i = instance_create(x,y,spear); with (i) { bla bla bla }
I'm not sure what variable I can check to see which sprite is used by the spear in the wall.

Any ideas?

Edited by Odb718, 31 October 2008 - 09:23 AM.

  • 0

#2 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 19879 posts
  • Version:GM:Studio

Posted 31 October 2008 - 09:24 AM

Well asign a temporary variable to spear and then use that to change it´s sprite image depending on your character... eg

var nnn;
nnn=instance_create(x,y,spear);
if sprite_index=spr_left nnn.sprite_index=spr_spear_left;
if sprite_index=spr_right nnn.sprite_index=spr_spear_right;

Is that any help?

EDIT: If there are more than two directions you could do this with a switch statement which is more efficiently...eg
var nnn;
nnn=instance_create(x,y,spear);
switch (sprite_index)
{
case spr_left:
nnn.sprite_index=spr_spear_left; break;

case spr_right:
nnn.sprite_index=spr_spear_right; break;

etc...
}

Edited by Mark13673, 31 October 2008 - 09:31 AM.

  • 0

#3 Odb718

Odb718

    GMC Member

  • GMC Member
  • 207 posts

Posted 31 October 2008 - 09:36 AM

Wow, not sure why I didn't check. I thought sprite_index was write only. Didn't even bother to see if I could "ask" what it was.
I got it working now, thanks. ::lmao::
  • 0

#4 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 19879 posts
  • Version:GM:Studio

Posted 31 October 2008 - 09:38 AM

No problem... Glad to help!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users