0 Favourites

How to make arrays of sprites

  • Hey guys,

    I read the arrays and loops tutorial, and also looked at the FAQ sticky regarding arrays. But I can't figure out something.

    I'm trying to create a chessboard, and so I thought an array of 8x8 sprites would be perfect. But I can't figure out how to implement it and make it work.

    I have an arraySquares object, width 8, height 8. I tried to populate it in a loop but either I must be doing something wrong or perhaps an array is not the right thing to use for this.

    I added an event with 2 conditions, OnStartOfLayout and For curLine from 0 to 7, and then System->Create Object->square on layer 1 at (400 + curLine * 35) and expected to see 8 squares there when the game runs, but there's only one.

    So please let me know what I'm doing wrong, or better still, what approach would you take if you wanted to draw a chessboard. Next steps I want to make other sprites drag-and-drop-able and they should "snap" to the right square.

    Thanks in advance.

  • loopindex("curLine")

    Also, are you providing both X and Y?

  • Hi:

       Check out the Path Finder plugin. It creates a grid in it's demo game. Sprites make their own collection, so an array may not be necessary. Also, Objects can carry their own variables, so you can add data fields to the object itself.

  • not sure if this would be 100% correct for bordlayout and loopreset but maybe it can help you

    you will need 2 framed squaresprite, 0 white 1 black and set origin at topleft

    /////vars

    offset=150

    yloop=0

    xloop=0

    for "create" 0 to 64

    create square at x: offset + square.width*xloop

                     y: offset + yloop*loopindex

                        add 1 to xloop

    if loopindex+1%2 = 0 set frame to 1 (division remainder = 0 / if even set frame black)

    if loopindex+1%8 = 0 add square.height to yloop and set xloop to 0 (if first row created set y position 1 square down

  • Thanks for the prompt replies guys.

    @vtrix: how can I add the "IF"s? When I click Add Action I can only add actions, not conditions. I can't figure out in what order to click the things to get it to work.

    Here's what I have:

    imageshack.us/photo/my-images/37/loopa.png

    But obviously the yLoop is incremented at the same time with the xLoop.

    How can I add a condition only for this action, what to click and in which order? It's not very intuitive.

    Thanks!

  • By the way I don't care about white / black squares just yet, I want to get it to work with the same color first.

  • About the checkboard just create a checkboard image 2x2 that is white black on top black white on bottom (or vice versa :D) and import it on construct as tiled background object.

  • Kiyoshi thanks, but I don't want the board to cover the entire layout.

    @vtrix: I got it to work after all, I added a sub-event (hadn't noticed the menu). Then I had to stop animation for the square, as it was going all black as soon as the game started.

    For reference here's what I ended up with:

    img51.imageshack.us/img51/4012/loop2j.png

    Thanks again, and I'll be back :D with more questions.

  • about the colors, it can be usefull later on when you want to check this... take the solution you think is best..

    about the ifs, it should be subevents of the loop, system compare

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Geo Just resize it as wanted. Or am i misinterpreting what you want ?

  • hmm, dont think the framesetting will be correct like you have it, you should use the loopindex expression, heh and ofcourse, they are square, so width and height are the same i just remembered from something i did a while ago <img src="smileys/smiley12.gif" border="0" align="middle" />

  • You can get rid of the ifs using conditionals:

    loopindex%2=0 ?white :black, but I think Kiyoshi's method would be better.

    Chances are you'll want to use an array, rather than a physical representation for ai anyway.

  • OK I think I wasn't clear, sorry for creating confusion.

    So, to clarify: The thing WORKS. I posted the image (http://img51.imageshack.us/img51/4012/loop2j.png) for reference, in case someone else wants to have a look at it. As it is posted there, it works and I have no more questions about it.

    For now, it works very well for my purposes.

    Thanks!

    Geo

  • if the thing works, it works, cheers

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Sprite Font Generator - v3
368 112,395
RetroDaddy's avatar
RetroDaddy
Unread hot topic
167 14,517
DMT2005's avatar
DMT2005
Unread sticky
1 Favourites
C2 Games made with CocoonIO
136 89,842
minhcuong's avatar
minhcuong