Have any questions?

+44 (20) 3540 6226

hello@appshed.com

Group

icon group
The "Group" object allows you to group sprites, images etc together. 

 

The benefits of groups are:

  • Objects that have similar behaviours are grouped together.
  • You can define events (such as a "Collide") for a whole group, rather than individual objects.
  • This means it is much quicker and easier to get repetitive tasks done.

 

How to add a Group object

  •  Click on the "Group" object.
    (It's in the purple square Game Setup collection)
  • An Object Name will be automatically assigned.
    You can change the name if you want.
    Object names must not have spaces or special characters, just alphanumeric and underscore or hyphens.
  • Click "Save"

 

How to use a Group object

  • When the group is created, the Action is called.
    Typically the Action contains JavaScript. 
  • The JavaScript can contain any valid code, including standard JavaScript functions, jQuery, app.js and phaser.io functions.
  • If the JavaScript code references any other objects (such as images or sprites), then you must ensure that the Group object is created AFTER those objects.
  • You can rearrange objects using the Move feature in AppShed. Simply drag the Group object below any sprites etc that are referenced in the code.

 

 

Teachers

 Groups are very useful, but you probably won't need them at first.

Your first few games can just use Sprites, Images etc. and you can start using Groups when you want to do something more advanced.

 

 

Sample code:

 

The following code is an example of the JavaScript code for a Group object:

for(var i = 0; i< 15; i++){
  for(var j = 0; j < 15; j++){
    // Create a rectangle x, y, w, h, color
    var rect = this.add.rectangle(j*30,i*30, 10,10 , "0x7A7A7A");
    // add the rectangle to the group
    object.add(rect);
  }
}

This will create a grid of images, duplicating an image called "image1". Images will be spaced 20px apart from each other.

 

 

  • Thursday, 10 March 2022

appshed name white text 250

Copyright © 2022 AppShed Limited

AppShed Support
Customer Support

We are online and available to help teachers/educators using AppShed. How can we help you today?

Chat, call or email support@appshed.com