Changing an instance, keeping the sprite index
#1
Posted 13 May 2012 - 08:41 PM
In my game, after a period of time an instance is changed into another one. Can anyone tell me
how to find out what sprite index the changed instance had? eg I have 2 objects Obj_Alien1, Obj_Alien2
and 3 alien sprites Spr_Alien1,Spr_Alien2,Spr_Alien3. On level 6 of my game i have used the code
sprite_index=choose(Spr_Alien1,Spr_Alien2,Spr_Alien3) so now all the Obj_Alien1 objects have random
sprites assigned to them. When one of the instances gets changed into Obj_Alien2 i need to assign the same
sprite index to it.
Many thanks
Paul
#2
Posted 13 May 2012 - 10:00 PM
...
Dunno why I listed that.
Are you changing the instance or the object_index? In other words, are you performing the create events and destroy events? If you're not performing the create/destroy events upon changing, you can use a controller object to target the alien, save its sprite_index to a temporary local variable (var temp;), change the target alien's object_index and then set its sprite_index to the value in the temp variable.
#3
Posted 14 May 2012 - 08:28 AM
// Create an instance of the other object nextObj = instance_create(x,y,Obj_Alien2); // Assign the sprite_index you surrently have to the other object nextObj.sprite_index = sprite_index; // And finaly destroy the current instance so it has "transformed" instance_destroy();
Hope it helped, if not, I don't understand what you want, but if it helps, be gentle and rep up this post
#4
Posted 14 May 2012 - 09:48 AM
Obj_Alien2 is the same as Obj_Alien1 but Alien2 moves towards and follows the players ship.All the Obj_Alien1 objects were created and placed in the room editor.
I assume my program changes one random instance of the Obj_Alien1 into Obj_Alien2 but i don't know which instances of Obj_Alien1 have what sprite index.
On the other levels it didn't matter because all the Obj_Alien1 objects had the same sprite index so Obj_Alien2 had the same.
Thanks again
Paul
#5
Posted 14 May 2012 - 10:03 AM
1) Avoid all the hassle and just use one object instead of multiple objects (yes, it can be done easily)
...
Dunno why I listed that.
Are you changing the instance or the object_index? In other words, are you performing the create events and destroy events? If you're not performing the create/destroy events upon changing, you can use a controller object to target the alien, save its sprite_index to a temporary local variable (var temp;), change the target alien's object_index and then set its sprite_index to the value in the temp variable.
Thanks for the reply, much appreciated. I am changing an instance of Obj_Alien1 into Obj_Alien2. All the Obj_Alien1 instances were placed and created in the room editor. On other levels it doesnt matter because all the Obj_Alien1 instances have the same sprite index Spr_Alien1 or Spr_Alien2 or Spr_Alien3, so Obj_Alien2 depending on which level you are on, has the same sprite index, but level 8 has randomly selected Obj_Alien1 instances with randomly assigned sprite index's. So I don't know which Obj_Alien1 instance is going to be changed to Obj_Alien2.
Thanks again.
Paul
#6
Posted 14 May 2012 - 10:04 AM
When you want it to change, do something like that:
// Create an instance of the other object nextObj = instance_create(x,y,Obj_Alien2); // Assign the sprite_index you surrently have to the other object nextObj.sprite_index = sprite_index; // And finaly destroy the current instance so it has "transformed" instance_destroy();
Hope it helped, if not, I don't understand what you want, but if it helps, be gentle and rep up this post
Thanks for your time in replying to me, much appreciated.Maybe it would be easier if i send you the game?
Obj_Alien2 is the same as Obj_Alien1 but Alien2 moves towards and follows the players ship.All the Obj_Alien1 objects were created and placed in the room editor.
I assume my program changes one random instance of the Obj_Alien1 into Obj_Alien2 but i don't know which instances of Obj_Alien1 have what sprite index.
On the other levels it didn't matter because all the Obj_Alien1 objects had the same sprite index so Obj_Alien2 had the same.
Thanks again
Paul
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











