Spawn an object across the screen (SOLVED)


I am trying to work out how to use one object and spawn it across the screen width but so that each spawned object that appears across the screen in a row is not overlapping the previous object before it.

so for instances it would be as follows (using the @ sign as a reference to the object)

@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @



Sorry for having to reply back to my own post, I could not see a way of editing my existing post.

further to this question , I have been using the create object method to achieve this, however at the moment I am working with trying to create a single copy of the object first and as I decided to place one instance of this object on the screen where I wanted the other same objects to appear next to each other, I cannot see to get the X and Y position from this existing object and then add to these accordingly .

As the objects are going to be placed at the bottom of the screen I tried also to use to the screen height - the objects height but the object never appeared on screen when I did this.

Any thoughts on this please?



You could do this in a loop. Devide the screen width by the width (maybe plus a little offset) of the sprite and use this as the end value.
Create a couter variable that adds the spritewidth on every iteration and use the position of the counter variable as x position for you created sprite object.

Hi Wendigo thanks for your reply.

I have tried a loop but that failed so I thought I’d best concertrate efforts on getting a single object to appear where it should and this is my main issue at the moment. I have already place a single instance of this object bottom left corner and have given it a point that is situated on its right side but when I reference this in the expression it is as though this object is not actually in the scene as the new object I am creating using this reference does not appear anyway.

I have also tried using the X and Y position of the current object on screen although that is what I thought I was doing but again I wonder now if this is not referring to that object because the new instance does not appear.



I hope this is what you were trying to achieve (see attachment) if not could you add a screenshot of the result you are trying to get? (2.36 KB)

HI Wendigo, thank you so much for this however I am unable to preview it as it appears that there are images in the bank that do not exist in the attached zip file. Are these needed or can I just remove them?

Since this post I removed the images and ran the project but I do not see any blocks appear on screen. This is not something to do with me running Gdevelop on the Mac is it ?

** EDIT **
I have used your logic and applied it to my project and it works apart from the last instance of the object going off the screen but I could either work out how to resolve that or try and make the first object also start off the screen if that is possible so that they both equal each other.

My next part I need to work out is placing them at the bottom of the screen.

** EDIT 2 **

On working on having the object go across the screen I used this logic :

ScreenWindowHeight() - object.height()

This appears to work but leaves a gap at the start of the screen at the bottom where the object should from .Any ideas why this would be ?



Worked this out, it seems as though the first instance of the object was the issue so I created a global variable to store the objects height and used this to calculate the position.

object.Width() and object.Height() can’t work until there is at least one instance of the object on the scene.

Thanks Victor it make sense now :slight_smile: