i want the back ground to keep moving left and repeating itself after a certain time.. possibly making it go faster, but i can not figure out a way to make that possible...
This can be accomplished with a few simple rules. This will assume you are using the iPhone landscape, but it will work with any orientation with some number adjustments.
Create a game attribute called "scrollSpeed" and set it to 100.
Create your background actor and add the image to the actor. In this case we will use a 480 x 320 image. Place the actor on the screen and set its x position to 240 and y to 160 (centered)
Drag the "Move" behavior into this actor and set its direction to move left, and its speed to game.scrollSpeed.
Create a rule like so:
When self.position.x is < 240 --Spawn actor Bacground -- x self.position.x + 480 -- y 160
Create another rule like so:
When self.position.x is < -241 -- Destroy
So basically this will make your background actor move left at the preset speed. If you want it to increase or decrease in speed, just change the game attribute "scrollSpeed".
When your background moves more than half way across the screen, you spawn a new background that is in the exact placement to match up with your current moving actor. This is why we spawn at position.x + 480 instead of just telling it to spawn at 480. When the moving background goes off screen, we destroy it so that it does not keep eating away at memory. We are setting this to happen at -241 so that it will ONLY be destroyed when the actor is COMPLETELY off the screen. This prevents gaps in the background.
This method works very well from my experience; however, you must be aware that continually spawning actors can affect performance. By destroying the actor when its done, we are helping this performance, but older devices could potentially have problems, but it seems to work just fine on my 3G.
Hope this helps! If you are confused, ill upload a quick demo!
Unfortunately it seems due to a recent update that the move behaviour stutters a bit which causes a gap in between the images that you are trying to loop. I tried for ages to fix it, but had to cover that from happening in order for it to look good.
Yeah, I did the same, making images too big so they'd overlap only to find the gaps eventually return anyway! Not sure why this little extra bit to the code works but it does!
I have it set up currently so that there is an image behind that fills in the gap when it appears so that it looks perfect, but obviously not a very nice workaround from a dev point of view.
When self.positionX < or = to -576, change attribute self.positionX to 1600 + 576 + self.positionX
I don't understand it myself so may not work. LOL. Actually... maybe you can't do it with images that big as I think they get killed when too far off the screen... give it a go anyway.
On exp jet I just made the background twice as big as my scrolling direction doesn't have to be but it gave me more room to draw the background so it dissent look as if it was repeating as often then set the background to wrap added a move behavior in the direction I wanted to move and had an attribute for the speed so it could be adjusted by the app
Comments
Create a game attribute called "scrollSpeed" and set it to 100.
Create your background actor and add the image to the actor. In this case we will use a 480 x 320 image. Place the actor on the screen and set its x position to 240 and y to 160 (centered)
Drag the "Move" behavior into this actor and set its direction to move left, and its speed to game.scrollSpeed.
Create a rule like so:
When self.position.x is < 240
--Spawn actor Bacground
-- x self.position.x + 480
-- y 160
Create another rule like so:
When self.position.x is < -241
-- Destroy
So basically this will make your background actor move left at the preset speed. If you want it to increase or decrease in speed, just change the game attribute "scrollSpeed".
When your background moves more than half way across the screen, you spawn a new background that is in the exact placement to match up with your current moving actor. This is why we spawn at position.x + 480 instead of just telling it to spawn at 480. When the moving background goes off screen, we destroy it so that it does not keep eating away at memory. We are setting this to happen at -241 so that it will ONLY be destroyed when the actor is COMPLETELY off the screen. This prevents gaps in the background.
This method works very well from my experience; however, you must be aware that continually spawning actors can affect performance. By destroying the actor when its done, we are helping this performance, but older devices could potentially have problems, but it seems to work just fine on my 3G.
Hope this helps! If you are confused, ill upload a quick demo!
-Kyle
Have two images side by side... the following is for two 480px wide images:
Have a move left rule then:
When self.positionX < or = to -240, change attribute self.positionX to 720 + 240 + self.positionX
That'll work
I spent HOURS finding a way to make images for the background to cover the gap..
Thanks for the tip, I'll test it soon.
Will be so glad if this works.
Thanks
When self.positionX < or = to -576, change attribute self.positionX to 1600 + 576 + self.positionX
I don't understand it myself so may not work. LOL. Actually... maybe you can't do it with images that big as I think they get killed when too far off the screen... give it a go anyway.
btw, I love your new game Max Vector! it's made with GS ?
Would that use a lot of memory?
Please help out
But, On Old Devices, It stills has a Gap.