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.

Newcomers AppGameKit Corner / Animated background and random moving platforms

Author
Message
Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 21st Jan 2015 19:26
I was probably using the wrong search phrases, but I couldn't find answers to these 2 questions:

1. Is it possible to have an animated background image? The game I'm creating just to get my feet wet and learn AGK2 is basically a top to bottom scrolling game where the player jumps from one platform to another as they appear, but as the background will never change I was wanting to just use an animated sprite. Basically it would be a waterfall made with a static blue background and moving streaks of water over that.

I've tried loading the animated sprite and it works, but as soon as it loads my animated character sprite, the background disappears to make way for the new animated sprite.

Is what I'm wanting possible, or should I just have a static background with each streak a separate animated sprite? Since I don't plan on having more than a few dozen streaks that wouldn't be much of a problem, but I guess I'm wondering why I can't just have them in one animated sprite behind other animated sprites.

2. I want the platforms the player jumps to to be generated in random locations and drop down from the top, but they will have to have maximum x and y distances from each other to account for the maximum distance and height the player can jump. Is it possible to code it so I don't have to manually code each level with exact locations of the platforms?

Am I trying to use the wrong tool (AGK2) to accomplish these things? I mean, I can still use it and do work-arounds, like manually coding each falling platform, but I'd prefer not to. Am I making this too hard for myself?

The reason I'm not just making it a scrolling game instead of what I've described above is partly because the animated background is made up of hand-drawn art that doesn't tile well due to natural inconsistencies in the medium used, and it's always the same waterfall that fills the screen.
paulrobson
4
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 22nd Jan 2015 09:44
1. I'm a bit puzzled why the background disappears to make way for the new animated sprite. I wonder if this is the problem ? It's all just graphics, the difference between 'background' and 'character' is in the code.

What you want is possible, I think. I would be slightly wary of too much animation. The best thing to do is to mock it up and try it. With phones especially, you can limit your market. I dug out an old android phone and stuck the player on it, and there was a big difference in performance compared to my Nexus 7 running the Benchmark demo.

2. Yes, it should be. You may have to experiment with random numbers (and some concept of difficulty) and keep tinkering until it comes out right.

AGK2 is an ideal tool for your project I think. The problems (with animation using up phone GPU power) would apply to any development system - it's to do with the phone, not AGK2.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Jan 2015 11:32
Quote: "I've tried loading the animated sprite and it works, but as soon as it loads my animated character sprite, the background disappears to make way for the new animated sprite."


Are you using the same sprite numbers, hence overwriting the first one you loaded? Or is your second sprite non-transparent and covering the first? Some code will help us help you.

Quote: "I want the platforms the player jumps to to be generated in random locations and drop down from the top"


Yes this is very possible. Let's say you want a random x value anywhere across the screen:

xPos = Random(1,getVirtualWidth())

or somewhere in the middle 50%

quarterWidth = getVirtualWidth() / 4
xPos = Random(quarterWidth, quartWidth * 3)


or somewhere on the right-third

thirdWidth = getVirtualWidth() / 3
xPos = Random(thirdWidth * 2, getVirtualWidth())


or between 100 and 200 pixels of the last platform (left or right):

xPos = RandomSign(100, 200)
if xPos < 0
xPos = getSpriteX(myPlatform) - xPos
else
xPos = xPos + getSpriteX(myPlatform) + getSpriteWidth(myPlatform)
endif


Quidquid latine dictum sit, altum sonatur
Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 22nd Jan 2015 15:15
Thanks paulrobson and BatVink!

I originally wrote the post while at work so didn't have access to my code. Aaand...I'm at work now, so...

paulrobson
Quote: "What you want is possible, I think. I would be slightly wary of too much animation."


I used the wrong terminology for the "streaks" of water. I didn't mean they were animated sprites, but moving sprites. As in the sprite itself is a single image and I'll just move it down the screen, so that will be somewhat better on resources, but I get what you mean. I was a little worried about performance, as well.

BatVink
Quote: "Are you using the same sprite numbers, hence overwriting the first one you loaded? Or is your second sprite non-transparent and covering the first? Some code will help us help you."


I'm still very new to this, so when I see "transparent" I imagine that you would be able to see the background through the character sprite, but I'm guessing that's not what you mean. I'll look into it.

I didn't start out using sprite numbers, but rather created them with names for the id (bgsprite, fishsprite, etc.), so that shouldn't be an issue.

I'll post the code when I get home if you need, but I may have found a different way to do what I want (I'll get to that in a bit).

Basically I used the CreateSprite code and gave it the id bgsprite for the background.

Then I used AddSpriteAnimationFrame for each frame and loaded each image for that frame in the same command.

I then used the PlaySprite command.

I did that for both animated sprites.

It ran the background animation, and then the images disappeared and it played the fish animation, and then it repeated the process.

So I tried using a single image for each animation and used SetSpriteAnimation.

It did the same thing, but added blank frames in the middle of the animation loops.

If I just use a static image for the background, the fish animation works great using AddSpriteAnimationFrame, but of course the background doesn't look like a moving waterfall.

I did not include anything that would suggest the transparent/non-transparent aspect of the second sprite.

What I played around with last night isn't ideal, but it will work if I can't figure out another way:

I just used a particle emitter to make the "streaks" of the waterfall. What I don't like about that is that even though it uses my own image for the particles, it compresses it into an unrecognizable distortion. It looks cool, but I was hoping to see the streaks in their correct dimensions.

Also, as the particles begin moving, it just looks like I turned on the faucet to get the waterfall going, so it doesn't start out as a full waterfall. Once it gets going, it looks great!

Then I just made sure the depth of the fishsprite was correct so it appeared in front of the particles.

With that many particles I don't know how it will affect performance. It plays fine on my Galaxy S4 using the APK player, but that's just with the static background, particles, and animated fish. And I'm not sure if that's indicative of the final performance.

But thanks for the code on my second question. I'm excited to try it out when I get home!
Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 25th Jan 2015 21:03
BatVink
Quote: "or between 100 and 200 pixels of the last platform (left or right):

xPos = RandomSign(100, 200)
if xPos < 0
xPos = getSpriteX(myPlatform) - xPos
else
xPos = xPos + getSpriteX(myPlatform) + getSpriteWidth(myPlatform)
endif"


This is more what I was wanting to do, but when I use the first line of your code, I get:

"randomsign" does not accept parameters (integer, integer)
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 25th Jan 2015 21:34
ah yes, it's just one integer, it generates a number between the number you specify and the negative of the number you specify. Press F1 on the command and you'll get a better explanation than I can give!

Quidquid latine dictum sit, altum sonatur
Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 26th Jan 2015 16:53
Okay, thanks!

Another question, if you could help me:

The "platforms" my character jumps to are small waterfalls made using particle emitters. Since I'm going to have a whole lot of those throughout the game, and each platform has 2 emitters to get the effect I want, will that be an issue like say with performance? So far I've created 3 with no noticeable difference.

And is there a way to attach those emitters to a sprite, or group sprites together, so when I place one I can just tell it to place one entity and that will include the emitters and the sprites?

Thank you for your help! I've already been able to lessen my work because of you.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Jan 2015 17:02
My answers here are limited somewhat by my own knowledge, as I've just got back into AppGameKit coding after a break of a few months (too busy with life in general!)

You could/should make your platform sprites as Kinetic physics objects. this allows you to move them completely under your control, without them being affected by other physical interactions (such as being jumped on). If you then connect them using CreateWeldJoint(). Moving one will move them all. The big disclaimer here is whether yo can use joints on Kinetic objects - that will need testing.

Quidquid latine dictum sit, altum sonatur
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 26th Jan 2015 17:13 Edited at: 26th Jan 2015 17:17
I had to test the theory to satisfy my own curiosity (you can copy and paste this code to test)

The first answer was no, moving 1 connected Kinematic object does not move it's sibling:




So then I made 1 kinetic, 1 Dynamic, connected them and moved the kinetic one. Success!



The 2 remaining questions are whether the dynamic one is sturdy and unable to wobble because it is attached to a kinetic object, and whether your logic can handle the management of 1 kinetic object to control all others.

As for the particles question...I think it needs a bit of experimentation. It should be OK

Quidquid latine dictum sit, altum sonatur
JLMoondog
Moderator
10
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 26th Jan 2015 17:21 Edited at: 26th Jan 2015 17:23
I wouldn't even worry about joints. I use static physic objects for my platforms in Santa Drop and manually create them every #interval and move them at #speed every loop. Create them off screen than delete them after they've crossed the screen. If it's an odd shape, make sure to make them a poly object.

I've published two platformers very similar to yours and that method works very well. I wouldn't use a particle emitter to make your platforms. I like to have complete control of how mine are created and react.

Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 26th Jan 2015 17:22
Okay, thank you so much!
Juxton
4
Years of Service
User Offline
Joined: 21st Jan 2015
Location:
Posted: 26th Jan 2015 21:49
JLMoondog
Quote: "I wouldn't even worry about joints. I use static physic objects for my platforms in Santa Drop and manually create them every #interval and move them at #speed every loop. Create them off screen than delete them after they've crossed the screen. If it's an odd shape, make sure to make them a poly object.

I've published two platformers very similar to yours and that method works very well. I wouldn't use a particle emitter to make your platforms. I like to have complete control of how mine are created and react."


I'm currently using the emitters to create small waterfalls that serve as one component to each platform. I tried using animated sprites, but just wasn't getting the effect I wanted.

Other than the emitters, the platforms consist of two sides and a bottom that have collision. When the character hits the sides, he dies. When he hits the bottom, he jumps. The only way I could find how to have the platform have three different collision actions was to have three different sprites. If there's another way, I'm all for it!

Again, I'm not at home, so I can't post any code if you need it, but here is the design of each platform:

Particle emitter the width of the platform for the falling water.
The sides run along side the waterfall on either side.
The bottom sits behind the waterfall (so I just created a sprite and didn't use an image as it will never be seen.
When the player jumps into the waterfall, he goes behind the falls and bounces off the bottom, and then pops back up out of the falls.

Another issue I'll need to take care of is if the player moves left or right while inside the waterfall he might hit the inside of the sides and die, so there might have to be two more sprites on the insides with different collision reactions (don't know if there's a better term), or I'll need to somehow disable player input while inside the waterfall.

So the main issue is that there will be several of these platforms, and rather than coding the location of each of the platform components for each of the platform positions, I was hoping to be able to group them all together and just code the position of a single object.

Then I'm back to my original reason for posting which was to see if I could have the platforms automatically randomly placed throughout the level, but be within a certain amount of pixels so the player could still jump to them.

I know I'm probably not using the correct terminology for a lot of this, and I'm aware that I may be making more work than is needed. But I'm open to suggestions.

Thanks for helping me out, guys.

Login to post a reply

Server time is: 2019-08-25 01:09:08
Your offset time is: 2019-08-25 01:09:08