How to set up arrays and sprites in code?

0 favourites
  • 2 posts
From the Asset Store
Two levels with two sistem Wave. with Source-code (.c3p) + HTML5 Exported.
  • Hi,

    I'm new to construct. Looks interesting so far. As a first project, I'm trying to convert a project that I'm working on for mobiles.

    The project requires that I set up a series of multidimensional arrays. The 3 dimensional array limit is a little restrictive and will require some rewriting of the code design, but it's nothing major. However, I'm not sure how to proceed on the programming side.

    The arrays are going to hold sprite ID data. The game will then use these sprites to build up larger sprites and tiles in the game.

    So, how do I create new instances of sprites/delete old sprites in code?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There are two actions to create an instance of a sprite.

    1) System -> Create object (in the manual under System Actions)

    2) <Sprite> -> Spawn another object (in the manual under Sprites/Sprite Actions)

    Create object creates the instance at a location you specify.

    Spawning creates the new instance at an imagepoint you specify on the spawning object. (For example, the bullet in the ghost shooter example in the Beginner's Guide to C2.)

    When you create or spawn the object it is the current instance, so that is the perfect time to save its UID into your arrays, as well as to change other properties. In the case of a spawned sprite, you may also find it useful to save the UID of the parent object in an instance variable on the sprite. That way you can easily pick all of the "children" of a sprite and move or destroy them at once.

    In both cases there currently needs to be an instance of the object in some layout in your project when the game starts running. You can delete it anytime after it starts. (This limitation may be removed at some later date.)

    To delete an old sprite, select the particular instance of the sprite using some method of your choosing and use the sprite's destroy action.

    As far as knowing how to procede, I'd suggest you do as many tutorials as you can stand at first, examine some of the example games on the arcade (the ones in the example category often have downloadable project files) and in the forum How Do I threads, and try recreating a few very simple games before you tackle something as ambitious as your project sounds. I think you'll save time in the long run.

    If you're used to programming with code, Construct 2 is a little bit odd to work with at first (especially selecting instances of objects) but once you get the hang of it, it is a delight and makes for very fast development.

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