How do I use array to store sprite coordinates ?

0 favourites
  • 15 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • Hello

    I'm trying to automatise the creation of a layout by using an array to store sprite coordinates and frame number.

    Here is how it works :

    - coordinates and frame numbers for sprites to display are stored in an array

    - loop fetches coordinates from the array to display sprites

    - loop fetches frame number to change sprite appearance

    Everything works fine except that loops continues to create new sprites every click at point 0,0 and I can't understand why..

    Any idea on how to fix this ?

    Construct3 file is here :https://www.dropbox.com/s/hb5wwyz13oikfyb/SpriteCoordinateArray.c3p?dl=0

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Your event #3 is executed on every tick. You need to put it as a sub-event under "AJAX On Completed".

  • Thank you dop2000 !

    I did this and no more infinite sprites are created. But this time, 4 rows are detectect in there array, as it should be, but 6 sprites are created, #0 in a location outside the layout I can't understand, and #5 at point 0,0. I can't explain this. #1 to #4 are correct

    Here's a screenshot and c3p has been updated

  • TabHeight has a value of how many rows your array has. So if the Array has 6 rows, TabHeight has a value of 6.

    When you do the loop in line 3, you should do from 0 to TabHeight -1, otherwise your loop is done 7 times and not 6.

    I have done several tutorials on Arrays to create a card game with battle grid.

    You might want to have a look at it if something isn't clear with Arrays.

    https://www.youtube.com/playlist?list=PLJdfdQL4meAmIRzTmoHcesxGGeun51TH8

    Check the titles and description of the videos to know which one might do for you. If you have time of course, it would be better to follow then since the beginning.

  • Thnks

    My array has 4 rows numbered from 0 to 3.

    I did what you wrote, from 0 to TabHeight -1 and its removes the last sprite on 0,0.

    But I still have this first hidden sprite #0 outside the layout at 580x-157 which are coordinates that are nowhere to be found in may array.

  • I think I get it : Sprite #0 is sprite i did put myself on my layout on the editor. I removed it and everything is fine now !!

  • Check if the sprite is there due to other events or because it's in the editor layout.

    Best thing you could do to perform a quick check is to disable on start of layout line.

  • I think I get it : Sprite #0 is sprite i did put myself on my layout on the editor. I removed it and everything is fine now !!

    Well, you typed faster than me :D

  • > I think I get it : Sprite #0 is sprite i did put myself on my layout on the editor. I removed it and everything is fine now !!

    Well, you typed faster than me :D

    You've been of great help BTW :)

  • I was wondering, In my array, I stored values like coordinates and opacity. But I'd like to store booleans to define sprite visibility. I tried using 0 and 1 but visibility is only a matter of True and False. How can I test 0 and 1 within my loop and turn it into False/True ?

  • > > I think I get it : Sprite #0 is sprite i did put myself on my layout on the editor. I removed it and everything is fine now !!

    >

    > Well, you typed faster than me :D

    You've been of great help BTW :)

    You are welcome :-)

    I was wondering, for the same result, can I replace 'for "x" from O to TabHeight-1" with something like 'for each "row of my array"' ?

    You could use the condition for each element, but I never use it. I prefer to have total control of the starting and end point of the loop, because I might want to exclude some values in the future. Let's say you don't want to put something in the cell at the boundary of a bidimensional array, then you do the loop from 1 to Array.width - 2.

    I have done some tutorials related to Array in my course to develop a card game with battlegrid, you might want to have a look at the various topic or even better follow it since the beginning, to see how I use arrays and why:

    https://www.youtube.com/playlist?list=PLJdfdQL4meAmIRzTmoHcesxGGeun51TH8

  • Thanks! I will subscribe to your channel :) point is I have a 13' laptop and it's very difficult to read the writings on the screen.

    BTW, Something else I need to do : in my array, I stored values like coordinates and opacity. But I'd like to store booleans to define sprite visibility. I tried using 0 and 1 but visibility is only a matter of True and False. How can I test 0 and 1 within my loop and turn it into False/True ?

  • Thank you, in the later videos I have increased the Construct font size to show better what I am writing.

    For your issue add a sub event, if sprite is visible, then Array.at(X,Y,Z) = 1, else 0.

    That should do the trick.

  • It perfectly does the trick. Thank you !

    Thank you, in the later videos I have increased the Construct font size to show better what I am writing.

    For your issue add a sub event, if sprite is visible, then Array.at(X,Y,Z) = 1, else 0.

    That should do the trick.

  • You are welcome :-)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)