Getting a sprite to appear at the position of another...

Post your own tutorials, guides and demos.

Post » Fri Jan 23, 2009 7:17 pm

In the test stuff I'm doing, I've got an invisible sprite marker called Start. On the start of the layout Construct is told to move a sprite to its X and Y position. However, this doesn't work. I suspect I'm doing something dumb but have no idea what. Can someone explain to me what I should do?
B
2
S
2
G
3
Posts: 158
Reputation: 1,566

Post » Fri Jan 23, 2009 7:47 pm

You should run the debugger and look at the sprIvoRobotnik object. You can see exactly what's happening. The minute you start the application, because it is created on the first layout and has a platform movement, it starts falling. Really really far, down and down, until it's also going really fast. So as soon as you get to your layout it's probably going fast enough to pass through stuff.

Deactivate the platform movement on the first layout, then activate it on the layer where you can actually start controlling him.

Secondly, and the debugger also shows this, sprIvoRobotnik is being positioned by the Start object left over from the first layout. Because it's global it still exists, and Start.X and Start.Y just so happens to refer to that one, off the bottom of the screen, instead of the second one you placed on the layout. To get around this, you can destroy the first start object on the first layout on start of layout, or simply delete it from the layout editor - it still exists on the other layout, so it won't destroy completely. However, since you're going to be adding more levels and positioning start markers differently on them, I would suspect you really dont want other start markers from other layouts hanging around, so don't make it global. That also fixes it, since non global objects are destroyed when you move away from the layout.

Remember, if things are going wrong, get the debugger out!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Jan 23, 2009 8:03 pm

Thanks for that one! Going to take a look at the Platform stuff Deadeye's done too - looks like a hitbox is a good idea.
B
2
S
2
G
3
Posts: 158
Reputation: 1,566


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests