Player Spawning at Different Points

Get help using Construct 2

Post » Mon Jul 06, 2015 6:24 pm

I'm having trouble getting my player sprite to spawn correctly.

The set up is like a multi-room house where each layout is a room. If you walk to a door it changes layouts to the room you walked to. Each room has multiple doors, so when it loads a new layout the game should spawn the player sprite at door leading to the room you just exited.

Here's what I tried: I have an exit sprite with an instance variable called "LeadsTo" that has the layout name that it leads to. When the player sprite collides with the exit sprite, it calls a function that uses that instance variable to know which layout to load. That part works fine. In "On Start of Layout" I have it spawn a player sprite at try to position it on the exit sprite that has the instance variable with the same value as the layout that the player just left. Nothing is spawning.

I'm not at a computer with Construct 2 right now, so I can't show exactly what I did.

Anybody have any ideas? I can't make one layout cover all rooms because that is just an example and was the easiest analogy for what I'm trying to accomplish.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Tue Jul 07, 2015 2:02 am

Here's a screenshot of what I'm doing:

Image
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Tue Jul 07, 2015 2:05 am

Are you creating the player object at the start of the layout, or is it on a global layer?
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Tue Jul 07, 2015 2:08 am

At first I had it just on the first level on the game layer (not global) and not on the second level. Spawning it at the exit wasn't working, so I'd have a sprite on the first level but not the second. Then I tried having the sprite on each level and now at least you can play each level, but it isn't spawning in the correct location except for the initial load into the first layout. Subsequent loads into that layout start where the sprite is placed, not where the exit is.

Does that answer your question? Sorry, my mind is fried right now after work.
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Tue Jul 07, 2015 2:23 am

Without being able to look at a capx of what's going on it's almost impossible to diagnose what's going on from a screen of some events. It's not clear where your CurrentLevel variable is set... If that is after the position function then that could explain why it's not working as you hope.
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Tue Jul 07, 2015 2:26 am

CurrentLevel is a global variable
B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Tue Jul 07, 2015 2:46 am

B
11
S
2
G
1
Posts: 79
Reputation: 842

Post » Tue Jul 07, 2015 11:14 am

As you have the events, when you go to a different layout from Layout1, you have not recorded where you came from, so on the next layout you try to create an object at Exit.LeadsTo where neither LeadsTo equals the previous layout's name. You could use On End of Layout and store the current layout's name in a variable, then compare that variable to the Exit.LeadsTo in the create function. There's another problem you will encounter when you fix that issue - when you create a player on top of an exit, the on collision trigger will fire and you'll end up travelling to a different room, only for the player to be created on top of an exit again, and so on, every tick...
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Tue Jul 07, 2015 1:55 pm

Hi!

I´m actually trying to do the same thing, and what I´ve done and which seems to work ok so far (even if I´m sure there is a smarter way of doing it), is something like this (pretty close to what you have done)

I have two global variables: DestinationX and DestinationY

I have an "Exit Sprite" with three instance variables: nextX, nextY and NextLayout.
I place the sprite where I want an exit to be.
Then I set the variables in that sprite instance to where I want the player to "teleport" to.

Then I have an event saying something like (if I recall correctly):

Player -On collision with ExitSprite -> set DestinationX to ExitSprite.NextX
-> set DestinationY to ExitSprite.NextY
-> go to Layout(ExitSprite.NextLayout)

And on each layout I have an event saying:
On start of layout->create player at DestinationX, DestinationY

Also, I noticed that I had to have the player sprites (I have a hitbox, a "movebox" and the actual animated sprite) on a separate layout not used in the game to avoid duplicate players to spawn in the layouts.
B
28
S
7
G
4
Posts: 20
Reputation: 3,819

Post » Tue Jul 07, 2015 4:06 pm

Colludium wrote:As you have the events, when you go to a different layout from Layout1, you have not recorded where you came from, so on the next layout you try to create an object at Exit.LeadsTo where neither LeadsTo equals the previous layout's name. You could use On End of Layout and store the current layout's name in a variable, then compare that variable to the Exit.LeadsTo in the create function. There's another problem you will encounter when you fix that issue - when you create a player on top of an exit, the on collision trigger will fire and you'll end up travelling to a different room, only for the player to be created on top of an exit again, and so on, every tick...

I actually have a CurrentLevel which holds where the player left from and an EnteringLevel (both global variables), and the Exit.LeadsTo is supposed to match the CurrentLevel, which the player just left. I can't check the capx right now, so I'm not sure if that is showing that. I did run into the problem you described once and it kept bouncing me back and forth between two layouts. I didn't know what was happening, so thank you for that explanation, it makes perfect sense!
B
11
S
2
G
1
Posts: 79
Reputation: 842

Next

Return to How do I....?

Who is online

Users browsing this forum: beohs, brunopalermo, MadSpy and 9 guests