source code for the plugins (specially Pairer)

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Wed Jun 22, 2011 6:36 pm

U can create an array of objects with the s plugin
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jun 22, 2011 6:45 pm

Here's a simplified example of what I was thinking.
[url:234di1dn]http://dl.dropbox.com/u/666516/spile.cap[/url:234di1dn]
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Mon Jun 27, 2011 9:49 pm


an example of how this could work if you're still interested in making the plugin is this
in main.h make a vector
vector<CRunObject*> myobjects;

then have an action that takes an object parameter
and just do
[code]
myobjects.push_back(params[0].GetObjectParamFirstInstance(pRuntime));//GetObjectParam is for CRunObjType* which is a type pointer as opposed to a specific object pointer
[/code]

and within  construct do a for each object in the subevent after doing whatever picking condition you need to add each one by one.  it's also possible to automatically get the entire list of picked objects automatically, but I can't think of how off the top of my head, and don't have the time automatically to go look up how.  if you search my posts in this [construct engineering] forum, and go to the oldest posts, you can find alot of useful replies from ashley when I was first starting out asking ten billion questions.

after you had the objects loaded in the myobjects vector you could access them by index, if you wanted to move them all into a row for instance you could do something like
[code]
for(int j=0;j<myobjects.size();j++)
{
     myobjects[j]->info.x=j*myobjects[j]->info.w;//w:width...the .info structure has pretty much anything useful you'd want to do with objects, and most is self-explanatory
     myobjects[j]->info.y=240;
}
[/code]

if you want to use the plugin generally, and want it to automatically get rid of objects destroyed in construct so you don't get a crash accessing invalid pointers
in runtime.cpp in OnFrame2()
you could do either
[code]
for(int j=0;j<myobjects.size();j++)
{
      if(myobjects[j]->info.destroying)//checking this in onframe2 is the last time this pointer will be valid, if the object is destroyed the pointer will be invalid the next tick
          myobjects.erase(myobjects.begin()+j);
}
[/code]
which would erase that index in the vector, and move all the rest back to fill the gap
or you could do
[code]
for(int j=0;j<myobjects.size();j++)
{
      if(myobjects[j]->info.destroying)
          myobjects[j]=0;
}
[/code]
this would leave that index there, but with no object, so you could do a line of object like before, for instance, and have a gap in the line, instead of having the other objects fill that gap, you would have to modify it to check for the existence of a sprite, again to avoid crashes for accessing invalid pointers like so:
[code]
for(int j=0;j<myobjects.size();j++)
{
     if(myobjects[j])//add this to check if the pointer is nonzero...if not, you "erased" it
     {
          myobjects[j]->info.x=j*myobjects->info.w;
          myobjects[j]->info.y=240;
     }
}
[/code]


lucid2011-06-27 21:50:30
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Previous

Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests