Pulling an actor into the middle of another one.

Non-platform specific questions.

Pulling an actor into the middle of another one.

Postby ResourceDragon » Mon Mar 05, 2012 4:12 am

I'm having trouble figuring this out. Say I have this 16 x 16 pixel hole, with a red line 3 pixels in from all sides.(Below)
square.png
square.png (228 Bytes) Viewed 791 times


What I want it to do, is when the player(Also 16 x 16) steps far enough in(The red line) That he is moved into the exact middle of the hole(slowly),
and then he changes to a different animation once he is in the exact middle of the hole actor. (...Hopefully without using more then one actor.)

Having trouble getting it working... Xd
ResourceDragon
 
Posts: 39
Joined: Thu Feb 16, 2012 2:17 am
Score: 0 Give a positive score

Re: Pulling an actor into the middle of another one.

Postby skydereign » Mon Mar 05, 2012 6:53 am

For this I would recommend a variable to hold the player's current state. Then, in a collision event, the player with the square, you check if the player is within range. You can use something like this to get the position variables.
Code: Select all
if(state==0 && abs(x-collide.x)<5 && abs(y-collide.y)<5)
{
    // MoveTo moving the Event Actor (player) to the middle (xy of the collide actor)
    state=1;
}

The point of state makes it so the MoveTo command only triggers when the player isn't already moving toward the center. And since you use MoveTo you can use the move finish event, which will change the animation of the player, and do anything else you need.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pulling an actor into the middle of another one.

Postby ResourceDragon » Mon Mar 05, 2012 9:41 pm

I tried your code, and few other variations, and it's not working the way I want it to. I forgot about MoveTo function, that solved about 99% of my problems right there. XD

I found a different way to do it, it's easier on the mind and shouldn't cause lag, if any. I just create all the holes as a background, and make an invisible square that's about half the size of the hole, and clone it and place it in the middle of the hole background.

Thanks sky. Xd
ResourceDragon
 
Posts: 39
Joined: Thu Feb 16, 2012 2:17 am
Score: 0 Give a positive score

Re: Pulling an actor into the middle of another one.

Postby skydereign » Mon Mar 05, 2012 10:04 pm

You're welcome. But why are you mentioning lag? If you managed a way that doesn't involve draw or collisions, then it would be more efficient (wouldn't contribute to lag). Otherwise the only things that would influence that is either the number of actors or smaller animations. Anyway, just to explain what I was getting at with that example, the collision code is set to repeat, so the code checks every frame if it is in the box you defined via the animation. If so it sets it to stop checking and move the actor to the actual center.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Pulling an actor into the middle of another one.

Postby ResourceDragon » Tue Mar 06, 2012 12:14 am

number of actors

Is what I meant for lag, but I won't have more then 20 on screen at a time. (I can turn the rest off with out of vision)

Yea, it worked as you said, but it was giving me trouble with what I wanted to do once it was in the middle. But I think I fixed it for now. XD
ResourceDragon
 
Posts: 39
Joined: Thu Feb 16, 2012 2:17 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest