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 Classic Chat / How can you repeat a Sprite ??

Author
Message
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 14:07
Hello,

Can anyone help with my code?

I would like the laser to shoot once and when it reaches a point on the x axis to then repeat itself. This would then go on and on until the player lost (havent got this far yet).

If anyone would be able to let me know where i have gone wrong as at the moment all that is happening is that the first shot is made, it gets to the point on the x axis and fires another shot but it doesnt go anywhere along the x but instead just starts repeatedly firing and sticking to the y.



Matt
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Nov 2012 16:31 Edited at: 30th Nov 2012 16:32
Your laser is positioning in the same place exactly because you are not using your variable names properly.

You get the location with this (storing in integer variables):


And then you position your laser with this:


GetPointerX/Y returns a float value and the SetSpritePosition function expects float values for the x and y positions. Change your 'x' and 'y' variables to 'x#' and 'y#'. Same for your 'ShipX' and 'ShipY' variables, make them 'ShipX#' and 'ShipY#'.

Why are you deleting and recreating the enemy sprites? That is a lot of work that doesn't seem to be necessary. All you need to do is reposition them.

And, you create a new Laser sprite every time you use it and never delete the old one. This is going to create a HUGE memory leak. You only need to create the sprite once, as you did at the beginning. Then just position it as you need to.

Cheers,
Ancient Lady
AGK Community Tester
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 20:09
Thanks for this, I still cannot seem to wt the sprite to work. I have taken your advice on the rest and its all good. Would someone be able to help? I want the laser to shoot once and when it gets to a certain point on the x axis it to then send another laser. I also want them to come out of the ship but to not more with the ship, so when it's fired the laser will carry along on the same y axis whilst the ship is moving around.

Matt
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Nov 2012 21:18
Can you show me your updated code? Did you make sure to change all instances of 'x' and 'y' with 'x#' and 'y#'?

I think your code might work like this (assuming that the laser is firing from the ship):


Cheers,
Ancient Lady
AGK Community Tester
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 21:31
That is perfect, thankyou AL

How did you learn the coding? I have tried to learn Android coding and its simply a nightmare, i do prefer this code, its a lot more logical but i think learning any new code is difficult.

Matt
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 21:37
How would i do it so that the laser stays on the same path when fired, at the moment the laser is fired and when the ship moves the laser moves with it

Matt
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 30th Nov 2012 22:37
Quote: "How did you learn the coding?"

I have a Bachelor of Science degree for which I studied Computer Science and learned about programming. And I have nearly 30 years of professional experience designing coding in a wide variety of languages and on many different types of hardware. (I apparently have a talent for computer languages.)

Cheers,
Ancient Lady
AGK Community Tester
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 30th Nov 2012 22:53
I think i would agree AL!!!

Are you able to help on the query i have with the laser moving with the ship

Matt
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Dec 2012 00:42
Quote: "How would i do it so that the laser stays on the same path when fired, at the moment the laser is fired and when the ship moves the laser moves with it"

This is the line that's causing that:
SetSpritePosition ( Laser, GetSpriteX ( Laser ) + 3.0 , ShipY#)

You call that line each iteration of your loop. What you want to do is only set the laser's Y position once. I'll let you work out how to do that. Here's a hint, the laser will need it's own x and y variables.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 1st Dec 2012 18:56
I thought you wanted it to move with the ship.

Hodgey got the right line to fix. Change it to this:


Two lines added, two lines changed.

Cheers,
Ancient Lady
AGK Community Tester
MattDroid Inc
11
Years of Service
User Offline
Joined: 28th Nov 2012
Location:
Posted: 5th Dec 2012 13:34
Thanks for this, sorry i was a bit confused myself i think when i wrote this

I have got to a point which i am happy with (for a beginner), the ship is controlled by the mouse (or finger) and moves up and down, when shooting the enemy ship it plays a exploding sound and then re-positions the enemy ship. I have set a timer for 30 second which then makes the sprite invisible and shows text in the middle of the screen saying game over. Oh and theres some funky music playing in the background.

I want to now create a menu and highscore page. I am a bit stuck as to where I start, does anyone have any info or good links? The ones i have found are pretty useless

Matt

Login to post a reply

Server time is: 2024-11-24 04:01:04
Your offset time is: 2024-11-24 04:01:04