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 / Better for performance?

Author
Message
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 6th Apr 2012 18:06
I'm working on a t2 app for the ios that I started on the pc. My game would run at 10 fps. I decided to start the problem over because I couldn't figure out the problem. Now that I'm changing up my code I'm wondering is it better to delete a sprite/text and recreate as needed or to set sprite/text visibility to zero?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 6th Apr 2012 18:19
For performance during play, go for visibility instead of deleting and recreating.

Cheers,
Ancient Lady
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 6th Apr 2012 20:55
set visibility to 0 and set position of sprite outside screen.

i do sprite cloning/delete on the fly and i have 512x512 sprites and it still plays at 60fps on ipad3!!!
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 7th Apr 2012 02:58
Thanks. So I should load n create all my sprites at the start of my game and set vis to 0 right? Then clone,position, and set vis to 1 as needed.

And speaking of sprite sizes my background scrolls. The test image I was using was 8027 X 516 but it was too big and got blurry so I chopped it down to 2523 X 320. It looks fine but I needed the long width so I can scroll throughout the whole level. What can I do about this?
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 7th Apr 2012 04:08
Quote: "And speaking of sprite sizes my background scrolls...
...What can I do about this?"

There is no reason your sprite needs to be bigger than your screen, no-one can see what isn't on screen so it's wasted.

You could try using a large texture with a screen sized sprite and use UV scrolling to scroll the sprite through the image.

Ultimately though, the best way is to tile the background - break it up into tile blocks and bring them on as and when necessary.
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 7th Apr 2012 12:47
aight....I kinda get what your saying. I'm gonna try to figure it this weekend and if I can't I'll be back on Monday to bug you guys.
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 11th Apr 2012 18:12
Marl I'm still a little confused on those two methods. I understand concept of breaking down a image into tiles but I don't what program to use to break it down. and for using a large texture with a screen sized sprite and use UV scrolling to scroll the sprite through the image....I don't even no what that means lol. What's UV scrolling vs offset scrolling? Where do I go to break down the image? I have the image attached.

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 11th Apr 2012 19:53 Edited at: 11th Apr 2012 20:02
That's some nice graphics you've got there.

But that's a big picture.

First thing, you really want to change the size of this to make the limits powers of 2. Less chance of smegging up the load.


UV Scrolling - a quick rundown

Normally when you use an image with a sprite, that image is scaled to fit the sprite exactly. But it doesn't have to.

You can use the image smaller than the sprite and repeat it to create a tile effect. You would use UV scrolling to offset the position of those tiles to make the pattern scroll.

You can see my demo of this feature here http://forum.thegamecreators.com/?m=forum_view&t=194972&b=41&msg=2323426#m2323426

In your case, you want the image to be bigger than the sprite so only part of it is visible at once. UV Scrolling in this case allows you to change which part of that image is visible.

It's probably easier to show you with some code that you can work through. Then if you're still not sure, I can deal with any particular part you're not sure about.

This will compile and run and do a little scrolling demo.

I used a resized version of your image for the demo. You can change the image used and it will sort it out in the mix

Also this does not fill the screen vertically as your image is higher in some places and I didn't want to mess with the overall content.



edit: add image inline, formatting

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 11th Apr 2012 20:00
And here's the project.

It doesn't contain your original image - which us HUGE.

But it has two adjusted versions.

testlevelResize.png - which is the original resized to 8192 x 512
testlevelPart1.png - which is just the first section

The second one has been cropped to fill the screen better, a small border added so you can see it shows all the way to the edge and then resized 4096 x 512 at 256 colours to keep the size down.

Enjoy.

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 11th Apr 2012 20:06 Edited at: 11th Apr 2012 20:11
This is a cap using testlevelPart1.png, which is probably closer to what you're looking for.

Will that do?

or do you need to me to do tiles as well

edit: embed image

Edit: YES looking back I used the screen width twice in the print statement.

Curse these human genes

It should be

not


But the scroll still works

Attachments

Login to view attachments
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 11th Apr 2012 21:38 Edited at: 11th Apr 2012 21:43
Thanks for the help!!! This project is for the ios and other mobile devices in t2, does that matter? I'm at work now so when I get home I'll try out the code. The pic is from scott pilgram vs the world lol. Its just a placeholder for now.
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 11th Apr 2012 21:56
remember that that ipod touch only has 256mb or memory!!!
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Apr 2012 02:02
Nice artwork!

"here is a an expression to remember - He who has the gold makes the rules."
Paypal disagreed!
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 15th Apr 2012 01:15
I tried to get it to run on my ipod but I keep getting an error in the thread that says EXC_BAD_ACCESS because it has a problem loading the image. I tried it with different images sizes as well. I translated your code into c++ and this is what I got

Attachments

Login to view attachments
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 15th Apr 2012 01:50
Unfortunately I don't know tier 2, and it's years since I did any C++ stuff, so can't comment on your conversion or use of C++

But the first thing that jumps out is that you've used Integers for everything.

It Might be killing the player with a divide by zero or something.

Only the image and sprite references should be Integers.

Try changing the rest to floats.
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 15th Apr 2012 02:14
nm I figured out y it wasn't running but now I'm trying to make it scroll.
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 15th Apr 2012 07:17
The image looks stretched out but im gonna try to fix it. Can you show me how to do tiles? Maybe that'll work better.
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 15th Apr 2012 12:59
At first,



You create screenw integer value, but don't assign any value to it. Means that it will be a random number (Quite high usually).



If it's 2.0 (float), then you should do this instead:



Also, doing this:



Not inside an function can produce errors / memory leaks (As it did to me).
Safer would be to put it into app::Begin( void ).


Your image looks a bit stretched, because you scale it.
I believe you have 4:3 display screen, so your sprite gets sized "wrongly".
Like, say it's base value is 1000x50. Then you scale it to be fullscreen and you'd get 4000x150 instead.

1000/50 != 4000/150

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 15th Apr 2012 14:03
CreateSprite() inside a function produces memory leaks???
Are you sure as all my LoadImage() and CreateSprite() are in app::Loop()
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 15th Apr 2012 17:12 Edited at: 15th Apr 2012 17:22
Quote: " Can you show me how to do tiles? Maybe that'll work better."

I could, but the problems you are having are not to do with the method - which works perfectly well with T1 code - but with the conversion to T2.

Tiles use more sprites and more variables and so will introduce more things to translate to T2.

As I said before you need to use floats.

UV Scrolling uses fractional values to set the position of the image in the sprite, Integers definitely wont work.

The stretching is due to the fact that

Needs to produce a float value. Which is kind of implied in the comment.

It should be


Edit:

You also set the scroll limiter (maxXPos) before you set the value for the screen width (screenw).
gsdblack
12
Years of Service
User Offline
Joined: 6th Dec 2011
Location:
Posted: 16th Apr 2012 01:43
Thanks guys I fixed the image. It looks 'normal' now but I'm thinking this might not fix my problem. My background images will still be large and long because my levels will be 'endless'and repeating. I think I'm going just go with a repeating bg image so now I need to figure out how to do that. I think I can convert the T1 tile code, I already did it for the uv scrolling and the swipe gesture from another topic.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Apr 2012 14:50 Edited at: 16th Apr 2012 15:20
Quote: "CreateSprite() inside a function produces memory leaks???
Are you sure as all my LoadImage() and CreateSprite() are in app::Loop()"

Creating sprites will only cause problems if it never stops. Hundreds of sprites can be created in one loop with little or no problem but if you create them every loop none stop you will have a slow down at some point. Loading images takes longer but also does not cause a memory leak.

Loading media should not be done during gameplay for obvious reasons but dynamically creating and/or deleting sprites is part of how all of my games work (more or less).

gsdblack, I would seriously split that image into power of 2 sized images that are no larger than 1024x1024 or you will definitely have problems at some point. You could make this work using about 3 sprites that move with the player. I'll try to make a quick example using your image if you like but basically you just move the background sprites and when they go offscreen you re-position them at the other side.

EDIT: Attached is a quick example of how this might work in Tier 1. Hope it helps!

EDIT 2: Excellent graphics by the way

Attachments

Login to view attachments
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 16th Apr 2012 15:56
I am only loading sprites ONCE at game start
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Apr 2012 16:08
Quote: "I am only loading sprites ONCE at game start"

I never said you did anything different

I was just saying that it's sensible to do things that way...

Login to post a reply

Server time is: 2024-05-08 15:57:20
Your offset time is: 2024-05-08 15:57:20