• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Array and instance id help

G

gamer_essence

Guest
So i asked a question about the a few days ago but now that i've implemented a new array I am having the same problem again.

So i have a system thanks to someone who helped me previously and this time i've simply added the rotation array to it. As shown in Screenshot_4. This is the create event.

Now in the room start event I have Screenshot_1. How would I implement the rotation for that instance when I create the object?

For proof of concept I had the assembly object that controls this draw all rotations for every instance. When i switch rooms the numbers stay the same which shows it works saving the image_angles as shown in Screenshot_2. But every way I try to implement this it always puts the image_angle to zero so they're all upright, when I want some to be sideways or upside down.
 

Attachments

C

CreatorAtNight

Guest
Please post your code in your post next time with code blocks, it's much easier to read your post if we don't have to go back and forth between tabs. And now I can't copy your code to show you how to fix it.
Objects don't have a rotation, so you would have to apply the rotation to the sprite that the object is drawing.

If you paste in your code I can show you how to do it.
 
G

gamer_essence

Guest
Yeah no problem. Also I am aware that objects themselves don't rotate it's just what's drawn does. That's why I've attempted to change the image_angle.

The Create Event for my assembly object:
Code:
inst_no = instance_number(obj_orbiter1); // Get how many instances of the object there are
for (var i=0;i<inst_no;i++) { // Loop through that number
   var inst = instance_find(obj_orbiter1,i); // Get the instance ID of each instance as we go through the for loop
   xpos[i] = inst.x; // Store the coordinates of the current instance in two arrays
   ypos[i] = inst.y;
   rotation[i] = inst.image_angle; // Stores the "rotation" of the object
}
The Room Start event:
Code:
if (room == rm_test)
{
    for (var i=0;i<inst_no;i++)
    { // Loop through how many instances we counted at the start.
        instance_create_layer(xpos[i],ypos[i],"instances",obj_orbiter1); // Create an instance at the correct positions
    }
}
I've tried numerous different ways to figure out how to rotate the image_angle when I create the new objects. Basically I have my Assembly room where I can throw in multiple pieces and parts and this code saves the x and y position and the rotation of all the objects, in this case they are only called obj_orbiter1 because I haven't implemented anything else yet. That's my next step. When I'm done with the Assembly room this object is created to save everything. It then switches to the next room where you test what you've created (rm_test). Just for some reason I can only get the x and y positions correct but not the rotation.
 
Are you aware that instance_create_layer() returns the instance id of the thing you just created (similar to your instance_find() code above)?

Code:
if (room == rm_test)
{
   for (var i=0;i<inst_no;i++)
   { // Loop through how many instances we counted at the start.
       var _iii = instance_create_layer(xpos[i],ypos[i],"instances",obj_orbiter1); // Create an instance at the correct positions
       _iii.image_angle = rotation[i];
   }
}
That should do the trick.
 
G

gamer_essence

Guest
Are you aware that instance_create_layer() returns the instance id of the thing you just created (similar to your instance_find() code above)?

Code:
if (room == rm_test)
{
   for (var i=0;i<inst_no;i++)
   { // Loop through how many instances we counted at the start.
       var _iii = instance_create_layer(xpos[i],ypos[i],"instances",obj_orbiter1); // Create an instance at the correct positions
       _iii.image_angle = rotation[i];
   }
}
That should do the trick.
No I was not aware of that, I'll give it a shot!
 
Top