How do I count number of objects around each instance?

Just started using Construct 2? Post your questions here

Post » Sun Apr 23, 2017 11:56 pm

This has been troubling me for a while...

I have a bunch of sprites (A) in a tile formation (20*20 sprites for a total of 400) and I want each instance of this object to count how many sprites (A) are around it, then set an instance variable (A) as that number.
All of the images in any of my games are self-created.
B
16
S
4
Posts: 12
Reputation: 935

Post » Mon Apr 24, 2017 1:24 am

See my example in minesweeper game: https://www.scirra.com/arcade/puzzle-ga ... weepy-8557
The sample show how many bombs around certain tile.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Tue Apr 25, 2017 1:01 am

@alextro

Thank you very much! You will be put under the "special thanks" part of my credits (currently only 4 in the entire credits!)
All of the images in any of my games are self-created.
B
16
S
4
Posts: 12
Reputation: 935

Post » Tue Apr 25, 2017 5:35 am

Sweet! Notice me when your game is available.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Sat Apr 29, 2017 12:51 am

@alextro

I am having trouble discerning what the put_bomb sprite does, and how it is found. I have made my own test to try to replicate the action, but it is not working.

https://www.dropbox.com/s/ttr75o5lkb8ya ... .capx?dl=0

Can you tell what is going wrong?
All of the images in any of my games are self-created.
B
16
S
4
Posts: 12
Reputation: 935

Post » Sat Apr 29, 2017 9:47 am

You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.
First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

here I edited yours: https://www.dropbox.com/s/qqm24kaef5s4s ... .capx?dl=0
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Sat Apr 29, 2017 10:29 pm

The program works great, but there are a few kinks.

https://www.dropbox.com/s/vpso173zbga4k ... .capx?dl=0

There is an action that changes the sprite's frame to the instance variable, and when it is run I get this.

Image

The problems are circled here:

Image

The problem seems very random... Maybe construct 2 is conscious.

(You may need to zoom to 50%-33% to view the whole image. Also, the program runs very slowly. Is it the amount of objects on screen? No, I attempted to make the grid smaller (3 by 3) and it still has lag.)
All of the images in any of my games are self-created.
B
16
S
4
Posts: 12
Reputation: 935

Post » Sun Apr 30, 2017 1:11 am

Please check the edited capx I put here:
alextro wrote:You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.
First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

here I edited yours: https://www.dropbox.com/s/qqm24kaef5s4s ... .capx?dl=0


It all went okay and fast.
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Post » Sun Apr 30, 2017 2:18 am

@alextro

alextro wrote:Please check the edited capx I put here:
alextro wrote:You should check sprites object in projects tree, put_bomb just a small sprite to set where the mines will be placed. There are some miss calculation in your capx.
First based on your sprite size, offset value should be set as 50 not 25. Then evaluating distance retrieved from pythagoras equation: ceil(sqrt(50^2+50^2)) will result 71.

here I edited yours: https://www.dropbox.com/s/qqm24kaef5s4s ... .capx?dl=0


It all went okay and fast.


I just redownloaded it and played it in debug, and it runs quickly, but still has errors:

Image

This image has only been cropped, and the code was not altered in any way. I ran the program again, with some random instances having an incorrect inst. var.
All of the images in any of my games are self-created.
B
16
S
4
Posts: 12
Reputation: 935

Post » Sun Apr 30, 2017 5:41 am

Removed unnecessary condition. Should working correctly now >> https://www.dropbox.com/s/xx9zkkps60z11 ... .capx?dl=0
ImageImage
B
108
S
49
G
23
Posts: 783
Reputation: 22,611

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest