How do I keep a top-down sprite on a platform?

Get help using Construct 2

Post » Sat Apr 28, 2012 11:59 pm

What I want to do is have a player sprite be able to freely move around specifically on this platform in a top-down game. However, it would have no way of escaping the platform or moving off of it.
What I have so far is code that enables the sprite to be controlled via the 8-direction arrow keys as long as its on the platform. If it tries to move off, some other code is supposed to reverse its movement the moment the sprite isn't colliding with the platform.
However, I came across the problem of the sprite still slowly moving off of the platform anyway.

Can anyone give me some pointers?
B
3
Posts: 4
Reputation: 283

Post » Sun Apr 29, 2012 2:42 am

Are you using physics? Sometimes if you mix physics with other behaviors things take on a life of their own. You'd need to turn physics off when using 8-Direction.

If that isn't it, you may need to post an example.
B
29
S
11
G
12
Posts: 281
Reputation: 11,888

Post » Sun Apr 29, 2012 10:28 am

How about using invisible blocks with the solid behaviour?

You'll just need to line them up where you dont want your player to be able to walk.

ImageImage
B
74
S
17
G
6
Posts: 1,039
Reputation: 10,605

Post » Sun Apr 29, 2012 1:13 pm

What I want to do is not let my character move off the platform using the 8-key directions, but instead move off when the mouse is clicked on another platform. Would the solid blocks allow that?
B
3
Posts: 4
Reputation: 283

Post » Sun Apr 29, 2012 3:01 pm

There isn't a way to disable the solid behavior, but you can move the walls out of the way for those times when you don't want them there.

Create two instance variables like startX, startY in the wall object. Then at start of layout set wall's startX=self.x and startY=self.y.

Then when the player clicks on the other platform, set the position of the walls to something off the layout like

walls->set position(-500,-500)

When the player has moved to the next platform, put the walls back in place:

wall->set postion(self.startX,self.startY)

You need to take care that the player doesn't get stuck in the middle of a wall when you put them back.

You also can just move the walls that the player collides with, but it is a bit more difficult to know when to put the walls back.

kittiewan2012-04-29 15:08:27
B
29
S
11
G
12
Posts: 281
Reputation: 11,888

Post » Mon Apr 30, 2012 2:49 pm

The problem described in this thread isn't exactly what you were talking about, but my example shows how to trigger the move of the solid object and move it back the way I described above.

Bounce and Jumpthru
B
29
S
11
G
12
Posts: 281
Reputation: 11,888


Return to How do I....?

Who is online

Users browsing this forum: makkancs and 25 guests