random object placement

For questions about using Classic.

Post » Mon Jan 18, 2010 9:33 am

Hi I am rather new to Construct and I wish to know how to make it so it creates explosions every 3 seconds at random between 1024 x 768 (the screen size, plus the scrolling so it follows the screen) is this possible to do and how?

thanks in advance.
B
1
G
2
Posts: 1
Reputation: 627

Post » Mon Jan 18, 2010 9:59 am

[code:fgbsn79e]
+ Every 3000 milliseconds
+ System: Create object explosionSprite
-> explosionSprite: Set X to random(1024)
-> explosionSprite: Set Y to random(768)
[/code:fgbsn79e]

Don't know what you mean about making it scroll, though. Objects scroll along with the screen automatically.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Jan 18, 2010 10:38 am

[quote="deadeye":3mcagpfl][code:3mcagpfl]
+ Every 3000 milliseconds
+ System: Create object explosionSprite
-> explosionSprite: Set X to random(1024)
-> explosionSprite: Set Y to random(768)
[/code:3mcagpfl]

Don't know what you mean about making it scroll, though. Objects scroll along with the screen automatically.[/quote:3mcagpfl]

I'm thinking he wants the explosions on screen locked to the scrolling and to continue on as the play area scrolls (like flying through AA flak during the war, explosions all around you). In which case Aquadragon, just do what deadeye said, but change the random size to take into account your entire play area. But remember you'll have to increase the speed or you wont see them as often. That and maybe copy the action a couple of times (looks pretty good with lots on screen at once, just needs some smoking trails on missiles and it'll be like BSG!).

Example
Download Cap
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Post » Mon Jan 18, 2010 12:22 pm

An alternate (and, in my opinion, better) method to have them occur within the bounds of the current screen is to use...

[code:1ag7n1xa]+ System: Every 3000 milliseconds
-> System: Create object Sprite on layer 1 at (ScrollXLeft+Random(1024), ScrollYTop+Random(768))
[/code:1ag7n1xa]

This will make sure the objects only spawn within the bounds of the screen. Lost My Keys' method will work, but it's not as efficient, and much less so as the layout gets larger. (Plus, there's no guarantee that the objects will actually spawn on the player's screen).

The "create object" command is found in system, and "ScrollXLeft" and "ScrollYTop" are also found in the "system" properties.

Edit: For a more pleasing effect where each explosion is also randomly offset in time, try something like... [code:1ag7n1xa]+ System: Every 2000 +Random(1000) milliseconds
-> yada yada[/code:1ag7n1xa]

This will have each explosion go off at not only a random part of the screen, but also a slightly random time.
B
3
G
3
Posts: 46
Reputation: 967

Post » Mon Jan 18, 2010 3:13 pm

Why don't you just use particles, and have the x, and y randomizer set to screen width, and screen height?
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Jan 18, 2010 6:51 pm

[quote="newt":20sfhf3s]Why don't you just use particles, and have the x, and y randomizer set to screen width, and screen height?[/quote:20sfhf3s]
This is probably more efficient. Still, add the scroll offset as Stargoat (lol) said.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Mon Jan 18, 2010 11:03 pm

[quote="newt":145ad5bn]Why don't you just use particles, and have the x, and y randomizer set to screen width, and screen height?[/quote:145ad5bn]

I guess it would depend on what you'd want to do with the explosions. If you wanted them to, say, interact with other objects in the game, particles wouldn't cut it. Also, I don't believe particles can have animations.

Edit:

[quote="Madster":145ad5bn]This is probably more efficient. Still, add the scroll offset as Stargoat (lol) said.[/quote:145ad5bn]

What's funny? :?
B
3
G
3
Posts: 46
Reputation: 967

Post » Tue Jan 19, 2010 1:13 am

I don't think he meant any offense... and Stargoat is a pretty funny name :)
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Tue Jan 19, 2010 3:35 am

it's awesomely funny. How do you guys land on your nicknames? I could never grow out of the first one I ever used.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Jan 19, 2010 4:18 am

[quote="Madster":2apd3k7i]it's awesomely funny. How do you guys land on your nicknames? I could never grow out of the first one I ever used.[/quote:2apd3k7i]

I picked mine cause I'd lost my keys at the time. They were under my hat, but I don't think to look in obvious places like that, heh.

You should start a where did your nickname come from thread :P
B
3
S
2
G
3
Posts: 628
Reputation: 2,531

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests