How to use array properly?

Get help using Construct 2

Post » Fri Apr 18, 2014 9:45 am

Well i was trying to learn how to work with arrays and used this concept on tile mapping.

Things i have done

Added array with 11X11 size
on Layout width 352 and height 352
for each xy element system will spawn sprite2 with default frame as green
if and array xy element has value 1 then sprite2 will turn frame to violet

and when "E" is pressed sprite2 which has frames as violet will spawn sprite 3 (orange)

but as i run the layout after each second the fps drops off and on debug mode the object count goes to 40 thousand and more.

for more reference see the image
https://www.dropbox.com/s/rxbf31psvkws4ve/Debugmode.PNG
https://www.dropbox.com/s/uqk64jamrgukh ... eCount.PNG
https://www.dropbox.com/s/bse8az9uyi55b ... 0value.PNG
https://www.dropbox.com/s/iyvsbmae49z61 ... 0Tiles.PNG

What actually i am trying to do!

Some array have value as 1 and i want system to spawn sprite3 on those array XY positions.

It should suppose to spawn one object! I am not sure what did i do wrong as i am not a programmer and this is my first encounter with fps fall and high cpu consumption!
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607

Post » Fri Apr 18, 2014 2:09 pm

You're spawning all those Sprite2's every tick. You need to add another condition to event 10 there so that it only runs once - like 'on start of layout'.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Fri Apr 18, 2014 3:49 pm

didn't work bro!

I tried 'trigger once' but it didn't work, and if i put it under sub event of 'On start of layout' it creates all the 121 sprites on XY 16,16.

if you permit me i'll send my capx file in PM.

Though thanks for your effort and help!
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607

Post » Fri Apr 18, 2014 6:25 pm

If you have no Sprite2 on the layout when that loop runs then Sprite2.Width and Sprite2.Height will return 0, which will spawn all the sprites at 16,16.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,630

Post » Fri Apr 18, 2014 6:32 pm

Thanks a lot @ramones that solved the issue. I have created two variables as height and width and set my default value. Volla Works like a charm but not without your help. :)

Thanks once again!
Aryan
Every Game is a Good Game it's just few people like and few does not! Keep coding people some day you will be a "NOTCH".
B
21
S
6
G
3
Posts: 85
Reputation: 4,607


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 15 guests