Containing a player inside a spawned sprite object

Get help using Construct 2

Post » Fri Sep 27, 2013 2:03 pm

This is related to previous discussion here: Invert solid + 8 direction

Basic thing Im trying to get to work: a randomly generated dungeon made up of decals of premade rooms. Problem: collision detection to keep the player within the rooms.

People kept saying in the first thread to border the sprite that I want the player to stay on top of with other solid sprites that are pinned to the base sprite. This works great. However, what I didn't say is that this base sprite may have several instances of it spawned at runtime. This would totally blow the bordering method up. Except that I discovered you can make container objects that hold other objects so that they are created, destroyed, and otherwise affected together as if they were one object. Yay! Except there's at least one snag- while angle of the original objects in the container is retained, the position relative to the container object is not! Boo! One of several questions I have is: how can I make that position stay as well? I tried storing the x and y offset in a pair of variables stored in the original solid bordering wall sprite, to be retrieved by each instance of that wall sprite when the instance is created. That works well, until you need more than one wall.
To make matters worse, there will be more than one kind of room.
Basically, each wall that is added complicates things, and each new room type multiplies that complexity. The only thing I can think of is that each room type has a several unique wall objects that are unique to that room- so we have massive numbers of objects now, each of which needs to be scripted to grab the positioning data from the original instance.

Ugggh! Is there a better way to do this?
B
11
S
4
G
1
Posts: 159
Reputation: 1,803

Post » Fri Sep 27, 2013 2:45 pm

Ok, so I've figured out a better way to do this, for anyone trying the same thing:
Forget bordering with sprites.
Set up an event to test for overlap of your player and your room you want to contain him in. Invert it. Now four lines in this event gets us what we want: 1) start ignoring 8 direction input 2)stop 8 direction 3)move 10 pixels at angle = player.angle+180 4)stop ignoring input
Now here's the trick, to get it so that the player sprite doesn't completely leave sprite before the event runs, you make the sprite size about twice the size of the actual graphic. So if your player is a 32x32 image, paste it into the center of a 64x64 blank image so he has this empty border around him. Then open that player image up in the C2 image editor. Change the collision polygon into a tiny box or triangle or whatever on the right hand side of the image (since C2 treats the right side as the forward side.) Now exit the image editor. What we've done is put a tiny little spot that moves in advance of the player's sprite that will set off our custom collision detection early, bouncing the player back 10 pixels whenever he tries to leave the containing sprite.
B
11
S
4
G
1
Posts: 159
Reputation: 1,803


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests