Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / [SOLVED] How to Move Sprite Array Group XY

Author
Message
ZapMan
11
Years of Service
User Offline
Joined: 1st Feb 2013
Location:
Posted: 11th Nov 2019 23:35
Using the Scene editor in AppGameKit Studio and the draw mode, I painted some square sprites I made and had them snapped and fit to the grid. I assigned them all to an array group, and am trying to find a way to move them all when I press an arrow button (essentially have the world move around my centered player sprite).

What I tried: I drew a map in paint, but figured it would be more work to add collision within a png than just painting the sprites on the scene editor. I was able to move the png around like I wanted with some code similar to this (the code currently has an error that I will explain in a bit):

//Left button
if GetRawKeyPressed(37) = 1
xlevel00 = GetSpriteX(GetSpriteImageID(gameScene_world)) + 50
SetSpriteX(gameScene_world, xlevel00)
endif

explanation: When the left arrow key is pressed a variable gets the X value of the specified sprite and adds a value to shift its location.
So where "gameScene_world" is, it used to be the variable name for my full map image, gameScene_world being my new array group. The error I'm getting is this:

"setsprite" [x and y] " does not accept the parameters (Integer Array, Integer)

So I understand I cannot use an array there to identify the all the sprites at once. Is there a way I can refer to every sprite in the group without specifically referring to each sprite? I'm trying to minimize code to make it simple and readable because I know I could just go do them one by one otherwise. Thank you.

The author of this post has marked a post as an answer.

Go to answer

ZapMan
11
Years of Service
User Offline
Joined: 1st Feb 2013
Location:
Posted: 12th Nov 2019 02:28
This post has been marked by the post author as the answer.
Nevermind I got it! Incase anyone else was trying to figure this out, I created a for loop to move all the sprites. Ill explain it below.



So I made two variables to hold the location of the sprite: xlevel00 & yLevel00. I also made another variable to store the max number of objects in the gamescene_world Array group that I made. I used that number to make the for loop execute for each sprite. I then set the position using those variables.

Login to post a reply

Server time is: 2024-04-13 16:56:21
Your offset time is: 2024-04-13 16:56:21