Ok now lets move things.
The most easy way to move things is using the build in behaviors.
So lets start over again.
Fire up construct.
Make a new direct X game.
Bring yourself to the layout editor.
Add and the box object.
(double click an empty place, choose box from the objects list, click to place it in the layout)
Now you have a rectangle with green borders.
Select the box.
On the left under properties uncheck the "transparent fill"
Click on the black square behind the "fill".
A drop down menu will appear.
Choose red as color.
Uncollapse "common" and name it "Bug"
There that is the object that we gonna move.
Now lets add a behavior that makes it move.
Still with Bug selected, on the left properties pane, uncollapse "behaviors", and click on "new behavior add"
<img src="http://usera.imagecave.com/j0h/26_bull.jpg">
A list with behaviors will pop up.
Choose bullet from the list.
The Behavior bullet will show up in Bugs properties. For now let all the values as they are.
<img src="http://usera.imagecave.com/j0h/construct/27_beha.jpg">
Position Bug close to the left edge of the layout.
Click the Events Sheet editor TAB on bottom left.
This brings you to the Events Editor.
Notice that there are NO events. And yet.
Click on the project menu. Click Run all in the Ribbon.
And watch Bug move from left to right.
Easy no ?
Now lets add one events to control Bug.
But before we do something about the Bullet behavior.
The Bullet behavior moves an object with the speed You gave it (in this case 250).
And in the direction it is facing.
Go back to the layout editor and lets check this.
Select bug .. and ...
You find the speed in the Behavior Properties.
The angles it is facing you find under Common. At this moment that is an angle of zero degrees.
NOTE: An Angle of 0 degrees is facing horizontal to the right of your screen. Remember this !
Take a look at the X and y position of Bug under common.
Move Bug to the corners of the layout and see the x and y update.
NOTE: The point where where x = 0 and y = 0 is on the left top corner of the layout. Remember this.
For now edit the x, y and angle values.
make x 300
make y 440
make angle 270
<img src="http://usera.imagecave.com/j0h/construct/28_up.jpg">
bug will update to its new positions and angle.
changing the angle to 270 will face the object Bug Upwards.
Run all, and u will see that bug will move upwards.
In other words, to change bug's move direction, all we have to do is change its angle.
Lets use this in an event.
First, change the "destroy when" under the bullet behavior to "never".
(dont forget to select the Bug in the layout)
Bring yourself to the events editor.
Add an event from the system object "always"
Add an sub-event from the Bug object
(right click the E-spot of the always event, choose add sub-event, choose Bug to start from)
When you are confronted with the events wizard asking you to choose a condition ..
notice there is a second tab now
<img src="http://usera.imagecave.com/j0h/construct/29_second.jpg">
For now we will not use it, so click on the bug tab.
Look for "Object is outside layout?"
Click finish.
Again this is a "flow-condition"
When the condition "is the object out of layout" is true,
every sub-event and action attached to this event will be executed.
Add an action to the "is outside layout event" ..
Choose the bug as object to start from ..
Choose "set angle" as action
and in the angle parameters window
fill in .angle - 180
<img src="http://usera.imagecave.com/j0h/construct/30_angle.jpg">
click finish
Strictly .angle - 180 is an expression.
But since we are not at the point to explain expressions in depth,
i keep the it simple.
.angle refers to the angle of the object that you choose in the first step of the action wizard.
Also named "self"
bug.angle is in this case the same, since you started the action off by choosing bug.
you can also use
self.angle .... but thats a lot of typing .. this why u can shorten it to just .angle
so .angle = its own angle
.angle - 180 = turn the object to opposite direction
you should now have this in the events sheet
<img src="http://usera.imagecave.com/j0h/construct/31_angle.jpg">
How to read this ?
When we run this ...
The bullet behavior will move Bug in the direction its facing with a given speed.
The events will first come to the "always" event.
That is a system "flow condition". It will always run the sub-events and actions attached to it ..
so next is the "is outside layout" sub-event.
This condition will run the action only if bug is outside the layout.
In this case the action is = .angle - 180 = reverse the direction Bug is facing to.
next will be again the "always" event.
and so on ....
Construct events run top-down and in a loop that never" stops.
"Run all" to see what we made so far.
And now for me it is bedtime, have a nice day.