[solved] Test sprite position from another instance ?

Get help using Construct 2

Post » Tue Feb 17, 2015 10:36 am

Hi.
I have a lot of blocks and their position follow a 32*32 grid.

For each block I would like to know if there are other blocks around it : top, top right, right, bottom right, bottom, bottom left and so on.

So I can modify the current block and set the right graphic on it.
For example, if a block has no other block to its top, top right and right, it has a slope (it will be a sprite special frame, nothing more) from top left to bottom right.

The same way, if it doesn't have any blocks to its right, bottom right and under it, it will has a slope frop top right to bottom left :

blocks.png


I don't know how to test each block position regarding other ones. Any (efficient) idea ?
You do not have the required permissions to view the files attached to this post.
Last edited by Coin-coin le Canapin on Tue Feb 17, 2015 5:23 pm, edited 1 time in total.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Tue Feb 17, 2015 11:25 am

I usually achieve this using functions.

I guess your top, top-right etc., blocks can be picked by some index variable relative to the current block...Otherwise you need to have some index variable depending on the instance id or while creating the blocks in the grid set a index variable for each block following a matrix notation(row number/col number).

Once a index variable is established for each block,

Then in a for loop, you need to check "for each" block --> pass the index variable of that block as a function param and call a function.
In the function (on the event side) pick the block for the top, top-right blocks depending on the passed index variable vs self-index variable --> (on the action side) do whatever you want with the picked blocks.

Hope this helps!
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Tue Feb 17, 2015 1:37 pm

I'm note 100% to understand all your explanations as I'm not fluent in english.
I did this following your suggestion :
blocks2.png


It tests only if there are other squares on the left, top left and top position.

And it takes way too much time : a few seconds for only 100 squares, and I have about 2000 squares in my layout.

How to improve it ?

Maybe could I put all my blocks in an array before instead of testing the actual squares ?
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Tue Feb 17, 2015 4:00 pm

Do you want to loopindex the logic on number of blocks or number of squares?

I also believe when you say 2000 squares you have them on a Tiledbackground...Otherwise performance will sure be impacted with or without the logic! Try to have as many less static objects as possible...

You can do the above logic only if the number of blocks you have are limited in number ( say less than 60 to 70 or so)...

Also you should call the function on a triggered event rather than every tick...otherwise performance will again take a hit.
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Tue Feb 17, 2015 4:29 pm

Hi,

Let me explain what I exactly want to achieve :D

I have a map :
map.png


Each square is a sprite. Well in the editor it's from a tilemap object because it's easier to draw large area with this.
When the layout is created, all the tiles are replaced by a block sprite. But that doesn't matter for my issue I guess.

So i have a level with a lot of squares and I would like to automatically have slopes on edges, like this :
blocks.png


And the blocks need to be sprites because I need to do some actions on them (change opacity and stuff) for other events.

I don't really care if it takes a few seconds to iterate over all my blocks to set up the slopes on edges because it will be done only once when the layout is created.

However, it will be done in smaller areas some time when a game occurs, because the blocks are destructibles. New edges will be created by the players so I'll need to change some blocks to slopes, but this is another issue at this time.

I'm currently trying using an array to do the work but I'm not done finishing yet so I don't know if it will be faster than the previous method.
I don't know if I explain well my issue :D

Edit : How dumb I am. I just have to do this while I'm on my big loop at the start of layout, I can check the tiles positions for each loop index.
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Tue Feb 17, 2015 5:03 pm

Well it is done and it was incredibly easy. Why do I focus on complicated things… :l

The events I used in my loop :
smoothedges_events.png


And the before/after (click on the picture) :
smoothedges.png
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276


Return to How do I....?

Who is online

Users browsing this forum: ST314 and 28 guests