Making a canvas draw all instances of a clone?

Non-platform specific questions.

Making a canvas draw all instances of a clone?

Postby Zehper48 » Sun Mar 06, 2011 11:25 am

Hello GE,
How can I make a canvas draw all instances of a cloned actor, at the moment it is only drawing the first one and non of the others.
Thank you
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby lcl » Sun Mar 06, 2011 11:42 am

Use this kind of code:

Code: Select all
int i;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("clones"); i ++) //Check all clones through.
{
    sprintf(actor, "clones.%i", i); //Set the name of actor to draw.
    draw_from(actor, 0, 0, 1); //Draw it.
}


Change "clones" to the name of your cloned character.
:D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby Zehper48 » Sun Mar 06, 2011 12:23 pm

Thanks alot for helping :)

Code: Select all
int i;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    sprintf(actor, "smile.%i", i); //Set the name of actor to draw.
    draw_from(actor,200+actor.x-Player1.x, 200+actor.y-Player1.y, 1); //Draw it.
}

Here is what i have now, but i have an Illegal structure on line 6,
The code for line 6 is to draw all clones of "smile" according to where they are in relation to Player1.
What am I doing wrong?
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby skydereign » Sun Mar 06, 2011 12:34 pm

Yeah, to do what you want to do, you'll need to use an Actor *. Would look like this.
Code: Select all
int i;
char buffer[50]; //String for actors name.
Actor* actor;

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    sprintf(buffer, "smile.%i", i); //Set the name of actor to draw.
    actor=getclone(buffer);

    if(actor!=NULL)
    {
        draw_from(actor->clonename,200+actor->x-Player1.x, 200+actor->y-Player1.y, 1); //Draw it.
    }
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby lcl » Sun Mar 06, 2011 12:43 pm

actor is now just string, not Actor.
That's why you can't get its coordinates.

Do this:

Global code:
Code: Select all
char actorName[50];

Actor * GetClone(char Name[50], int num)
{
    sprintf(actorName, "%s.%i", Name, num);
    return getclone(actor);
}

Then give name to it and click add.

And now your script:
Code: Select all
int i;
Actor * this;
char actor[50]; //String for actors name.

for (i = 0; i < ActorCount("smile"); i ++) //Check all clones through.
{
    this = GetClone("smile", i);
    sprintf(actor, "smile.%i", i); //Set the name of actor to draw.
    draw_from(actor,200+this->x-Player1.x, 200+this->y-Player1.y, 1); //Draw it.
}

Now it works because now you deal those positions with actor itself, not its name. :)

EDIT:
Seems you just were faster again, skydereign...
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby Zehper48 » Sun Mar 06, 2011 1:17 pm

skydereign, I tried using your code, Thanks so much for helping me out, I didn't get any errors, but my clones didnt appear in the canvas

Lcl,
when i enterd the method into the global code it said
undeclared identifier actor line 5

I attached my game, if you could take a look at it, i would greatly appriciate
Attachments
Halo Boxhead Arena.zip
(204.83 KiB) Downloaded 85 times
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby skydereign » Sun Mar 06, 2011 1:24 pm

Umm, weird. They did for me. Here is your ged with the code inserted.
Attachments
Level1.ged
(6.4 KiB) Downloaded 75 times
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby lcl » Sun Mar 06, 2011 1:27 pm

Zehper48 wrote:skydereign, I tried using your code, Thanks so much for helping me out, I didn't get any errors, but my clones didnt appear in the canvas

Lcl,
when i enterd the method into the global code it said
undeclared identifier actor line 5

I attached my game, if you could take a look at it, i would greatly appriciate

Yeah, sorry. That global code thing last line.. change actor to actorName :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby Zehper48 » Sun Mar 06, 2011 1:28 pm

It was the order i had the code inserted! Haha didn't think It would make a difference for that instance, but it works now!
Thank you so much! =]
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Re: Making a canvas draw all instances of a clone?

Postby Zehper48 » Sun Mar 06, 2011 1:31 pm

Thank you both,
Both the codes work perfect!
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest