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 / Grouping media content within a function and then calling it.

Author
Message
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 27th Mar 2015 21:08
Hey again.

I've started a new fresh file. I've added additional AGC files; Menu, Media, Game and the like.

I've just noticed, i can make a set of functions, and even subroutines and then simply add the lot within another function. I then use THIS function within the "Do" loop and it'll load the lot. That's rather cool.

The question i'm asking is: Can i house all my game menu media, i.e. The sprites, the position of the sprites, etc within a function (let's call this function media()) and then simply load the function at the start of the 'Do' loop?



Now i've tried doing this, but one of my other subroutines, that use those sprites, would no longer work, although it works fine when the sprites are left as is within the main.agc. I hope you understand what i'm trying to say lol.

Thanks.

Khadin
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 27th Mar 2015 23:10 Edited at: 27th Mar 2015 23:13
Ok, think i've cracked it. I did the following function:



Now when i put the function: bluePlane() within the todo loop, it loads yay.

EDIT, slight problem. It loads the plane, but i'm getting no animation. It's just a static sprite.

Khadin
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 28th Mar 2015 22:49
The function beginGame() has bluePlane() within it. With the following code, the plane is now annimated.

do
mainMenu()
if GetPointerPressed()=1 and GetTextHitTest (gameStart,GetPointerX (),GetPointerY ())
PlayMusic(taptap)
backdrop = createsprite(10)
SetSpritePosition(backdrop,screenW,0)
SetViewOffset(screenW,0)
beginGame()
endif
sync()

loop

Problem i'm having now is: I have the MainMenu() function, which loads within the first screen. When you click 'Game Start', the game jumps to SetViewOffset(screenW,0) which is the screen to the right. The plane loads, it's animated, and i have a new backdrop. Now, i can't get my plane to respond to my controls, and i've tried everything. If i kept my plane on the first screen (Setviewoffset(0,0) the plane works with the following code:



I know it's something to do with the setspriteposition, but i'm unsure how to get the controls to work on the following screen. Please help.

Khadin
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 28th Mar 2015 23:13
GetTextHitTest expects World Coordinates, GetPointerX/Y return View Coordinates. The function ScreenToWorldX/Y will convert the coordinates to your current view.
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 28th Mar 2015 23:37
Can't say i understand. Let me explain a bit more. I can now get the plane, to go to the next screen, and i've got the screen to scroll whilst being able to fly up or down, via the following code:



I just want to get it to now fly from left to right.

Khadin
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 29th Mar 2015 00:38
if GetPointerPressed()=1 and GetTextHitTest (gameStart,GetPointerX (),GetPointerY ())

won't work if SetViewOffset() is anything other than the default coordinate of 0,0. you would have to write...

if GetPointerPressed()=1 and GetTextHitTest (gameStart,ScreenToWorldX(GetPointerX ()),ScreenToWorldY(GetPointerY ()))

If for example you write SetViewOffset(100,100), then although the top left coordinate of the screen is now at coordinates 100,100, clicking on the top left corner of the screen will still return the coordinates 0,0 with GetPointerX and GetPointerY, because they are coordinates on the actual screen area rather than a position within the world.
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 29th Mar 2015 02:46 Edited at: 29th Mar 2015 02:50
Hey Mike. I know nothing about ScreenToWorld, so that's helped, just can't digest it at the moment as it's almost 2am here But, as the forum moves really slow, and i'll be coding tomorrow, i need to ask:

Will that do anything about me not getting my plane to move from LEFT to RIGHT, and vice versa, when i; SetViewOffset(screenW, 0) - ScreenW is the 1366 (Laptop) I can get the plane to go up and down, np. I can also get the plane to go left and right when i keep to the first screen - SetViewOffSet(0,0). Hope i'm making sense.

my first screen, is the game menu. Clicking Game Start, moves the screen to the right - From setviewoffset(0,0) to setviewoffset(1366,0) (Numbers might be off, as it's late) This is where my Plane sprite is.

As i say, i'll be coding tomorrow, so i'll try what you've said above.

Khadin
Mike Archer
9
Years of Service
User Offline
Joined: 19th Feb 2015
Location: Wales
Posted: 29th Mar 2015 05:41
It's important when using SetViewOffset() that you understand the difference between World & Screen coordinates, as it may lead to numerous errors otherwise. They say a picture is worth a thousand words, so I hope the attached JPG helps

Attachments

Login to view attachments
Khadin
9
Years of Service
User Offline
Joined: 13th Feb 2015
Location: Nottingham
Posted: 29th Mar 2015 18:14 Edited at: 29th Mar 2015 18:15
Omg Mike. You are a freaking genius. This is what, the third time you've got me out of a hole. I use the following code, and it now works!



Genius dude, thanks.

Khadin
Greenwich
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location:
Posted: 29th Mar 2015 18:20
That illustration is just perfect, Mike. Thanks.

It's mean time. *averages*

Login to post a reply

Server time is: 2024-04-20 04:48:50
Your offset time is: 2024-04-20 04:48:50