While THIS happens DO that?

Get help using Construct 2

Post » Sun Dec 25, 2011 5:21 am

I'm in the process of making my game on Construct.

See the game in action (Flash)

I'm able to drop a ball each time I click.

But I don't know how to:

    > Stop the click event while the ball is moving.
    > Kill the ball one second after it stopped moving.


Note: I'm using Physics.

This is what I have so far:
lonrot2011-12-25 07:31:16
B
4
G
1
Posts: 53
Reputation: 708

Post » Sun Dec 25, 2011 8:21 am

Hi Ionrot,

Take a look at this capx I made for you.
it will show you how to :

> Stop the click event while the ball is moving.
> Kill the ball one second after it stopped moving.

Lucky Hit capx

Just a quick and dirty capx to show you how it works.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Dec 25, 2011 6:41 pm

Great Maxum! I have one question.

When Ball.X and Ball.Y match 0, they become oldX and oldY, right? How this have to do with the current speed of the ball? To my understanding zero would be a location in X and Y axis, which is the top left corner, and not a value of movement.

Thanks again, I hope you can clear this up for me. lonrot2011-12-25 18:42:59
B
4
G
1
Posts: 53
Reputation: 708

Post » Sun Dec 25, 2011 9:34 pm

In maxum's capx, he stores every tick the position of the ball, at the end of the event sheet. So if at the next tick, the position of the ball is the same (ie : the ball doesn't move anymore) oldX and oldY will equal actual X and Y position. He use these condition to check if the ball stopped.

But there's an easier way to do that
Code: Select all
System: Ball.Physics.VelocityX = 0
System: Ball.Physics.VelocityY = 0
    -> Ball: Destroy
    -> System : set OKToDrop = 1

Also, while I'm at it, I would say that the OKToDrop variable is useless, you just have to check the Ball.Count value (which returns how many ball there's on the scene)
Also he could replace event 2 by
Code: Select all
System: Every tick
    -> Balldroper: Set X to Clamp(Mouse.X,25,300)
    -> Balldroper: Set Y to 18


Well in short that would look like that
maxumsEnhancedLuckyHit.capx
Last edited by Yann on Sun Sep 14, 2014 10:39 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Dec 26, 2011 2:30 am

Thanks Yann for your input on this. As always you have a more elegant and efficient way to solve these problems.

Have a merry Christmas and a happy new year.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Mon Dec 26, 2011 2:55 am

the problem ive got with velocity x velocity y is they work only on the x y axis, what about something that is moving in cross motion, the only solution i could think is having some distancevelocity vtrix2011-12-26 02:56:31
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Mon Dec 26, 2011 9:15 am

This game seems cool :)

Let us know when you've the final version :)
B
18
S
4
G
5
Posts: 149
Reputation: 4,498

Post » Mon Dec 26, 2011 10:47 am

@vtrix:
VelocityX and VelocityY are vector components, every movement can be broken up into 2 axial displacements.


For instance if VelocityX = VelocityY and they aren't equal 0, the object moves diagonally.Yann2011-12-26 10:48:29
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Dec 26, 2011 7:00 pm

Thanks Yann, velocity makes more sense to me, and it's easier to read.

Is there a way to add an ELSE / OR statement bellow VelocityX and Y conditions? I can make a separate function, but it would be nice to see a cleaner code. The ELSE statement is intended to kill the ball if it goes away from the stage (stage width 300px, stage height 600px)lonrot2011-12-26 19:22:04
B
4
G
1
Posts: 53
Reputation: 708

Post » Tue Dec 27, 2011 12:48 am

There is no ELSE statement as it is, but you can use the regular events.

In our case,
ball.x < 0 //Left boundary
... Ball => Destroy
ball.x > 300 //Right boundary, you can also use "layoutwidth" or "windowwidth"
... Ball => Destroy
ball.y < 0 //Top boundary
... Ball => Destroy
ball.y > 600 //Bottom boundary, you can also use "layoutheight" or "windowheight"
... Ball => Destroy

This way, if the ball is out of boundaries, we destroy it.

Layoutheight/layoutwidth and windowwidth/windowheight are system expressions.Kyatric2011-12-27 00:49:28
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Next

Return to How do I....?

Who is online

Users browsing this forum: gregorysforster, jeffige, Matthew de, onzephyr and 0 guests