How do I make a coin ramdomly appear on BG layout?

Get help using Construct 2

Post » Sun May 15, 2016 1:17 am

hi, guys. i am making a simple game where you collect coins. i want a coin to randomly appear within the background layout after its has be collected by the player. player collides with coin, coin get destroyed scoring 1 point for player then immediately 2nd coins appears randomly on map and so on still players dies. thanks
B
4
S
1
G
1
Posts: 3
Reputation: 800

Post » Sun May 15, 2016 1:46 am

You could create another coin instance at location (random(LayoutWidth), random(LayoutHeight)) when the player collides with a coin. Presumely, this should be after when you would do the action destroy coin in the collision event.

But the random coordinate above will sometimes create the coin at undesirable locations such as at the edge of the layout. This could make the coin appearing only partially on the layout. If you don't like this, you will want to add the size of the coin into account, so:

Assuming the hotspot of the coin is at the center,

coinWidth/2 + random(LayoutWidth - coinWidth),
coinHeight/2 + random(LayoutHeight - coinHeight)
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Sun May 15, 2016 2:07 am

thanks for the reply! how exactly do i do that? can you give me a run through cause i am new to this! do i need to create a global variable to do this? so confused. Edit: i figured out how to re spawn the coin after it collides with the player but now the coin sometimes doesn't show on the layout. i think its spawning out side the layout! i tried the code you wrote in your post and it said there in variable named coinwidth and height :?:
B
4
S
1
G
1
Posts: 3
Reputation: 800

Post » Sun May 15, 2016 5:31 am

You are new to this? Have you seen https://www.scirra.com/tutorials/37/beg ... onstruct-2 This is the basic foundation of C2 that you must understand before attempting to make anything else.

but now the coin sometimes doesn't show on the layout.


EDIT: just saw your edit. Can you check for the location of the coins? See Debug Preview and check where are the coins. (...or are there no coins?)
I got a game that you multiply, breath fire with two heads and brawl foes to oblivion with your clones: http://www.newgrounds.com/portal/view/660664 (use Chrome on Windows for best performance)

My sites:
http://twinblazar.deviantart.com
http://twinblazar.newgrounds.com
https://twitter.com/twinblazar
http://www.pixiv.net/member.php?id=15072448
B
30
S
11
G
11
Posts: 411
Reputation: 8,469

Post » Sun May 15, 2016 5:48 am

TwinBlazar wrote:You are new to this? Have you seen https://www.scirra.com/tutorials/37/beg ... onstruct-2 This is the basic foundation of C2 that you must understand before attempting to make anything else.
lol i will start straight away

but now the coin sometimes doesn't show on the layout.


EDIT: just saw your edit. Can you check for the location of the coins? See Debug Preview and check where are the coins. (...or are there no coins?)


they are spawning out side the layout. i just don't know why!! does the layer matters?
B
4
S
1
G
1
Posts: 3
Reputation: 800

Post » Sun May 15, 2016 6:12 am

Check out my games on Google Play:
BEAST ATTACK (1,000,000+ downloads!)
ZOMBIE BASH (Android) (Launched Feb 17)
ZOMBIE BASH (iOS) (Launched March 17)
B
54
S
18
G
2
Posts: 436
Reputation: 5,582


Return to How do I....?

Who is online

Users browsing this forum: David181, OBLIVION and 59 guests