Sprite Movement

Get help using Construct 2

» Thu Dec 08, 2011 5:04 pm

Can someone give me a hint on how to do the following:

1) I have three sprites, that will start moving from the center of the screen to the left on the start of the layout. They have the 4 directions (left, right, up, down) and are bound to layout.

Q: 1) How do I detect that they hit the left boundry?
2) Move all of them at that point down by by y pixels?
3) Change the direction for all three of the sprites to right?

Also, how could I do an effect like in space invaders when the shield gets hit by a bullet, it gets partially destroyed? Do I have to make multiple PNG and test for the collision, and display different frame, or is there an easier way that does this dynamically?

B
4
G
1
Posts: 3
Reputation: 731

» Thu Dec 08, 2011 5:34 pm

1) assuming the pivot is in the center of the sprite
[code]foreach Sprite
Sprite.X >= LayoutWidth-Sprite.Width/2
-> Sprite: set touchBoundary to true
-> Sprite: set yStart to Sprite.Y[/code]yStart is an instance variable

2)
[code]Global variable yPixels = 100
Sprite: Y position is lower than Sprite.yStart+yPixels
Sprite: is touchBoundary
-> Sprite: set Y to Sprite.Y+50*dt[/code]
will move the sprite by 100px down at 50px/sec

3) how do you move them to left in the first place?

I think you can achieve this effect with the canvas, by pasting your shield on start of frame, and then pasting a destination out blowing sprite on top of it to erase them.Yann2011-12-08 17:35:28
B
71
S
22
G
14
Posts: 1,494
Reputation: 16,660

» Thu Dec 08, 2011 5:43 pm

1. Not sure what you mean, but I think you would just compare the x value. Like spite.x< n.
2. Depending on your movement style you would just reference sprite.y + n amount.
3. There are 2 way I can think of, but until families, or containers are implemented it can be a bit tricky. Right now for the first method you could add a bunch of sprites to be the barrier, and have them always set position offset from the main sprite. To do that you would need to use index's like barrier(0)set position to mainsprite(0).x+n,mainsprite(0).y+n, and barrier(1)set position to mainsprite(0).x+n+n,mainsprite(0).y+n+n. For the second, which is easier, you can make a bunch of frames, and have that non moving animation set position to the main sprite. Then on collision you just change the barrier's frame to the next.

Also Ninja Yannnewt2011-12-08 17:45:16
B
178
S
50
G
205
Posts: 8,684
Reputation: 127,211

» Thu Dec 08, 2011 8:53 pm

I had System On start of layout do a Simulate 8Direction pressing Left for the object, but that did not seem to work. So I set another System event for Every tick to do the same.
B
4
G
1
Posts: 3
Reputation: 731

» Fri Dec 09, 2011 8:04 pm

Thanks for the responses and suggestions. Will try it over the weekend.
B
4
G
1
Posts: 3
Reputation: 731