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 / questions about sprites

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Apr 2013 23:42
Question 1
I'm using an animation sprite to build a tilemap. I set the frame to the corresponding tile number, then I draw the sprite. No issues here. But, the main sprite itself still draws onto the screen and I don't want that. If I try to hide the sprite, it also hides any instances where I tried to manually draw it. (unlike DB where I can hide a sprite but still paste it) So is there a way to fix this?

Question 2
I discovered the setSpriteScissor command to set up a clipping area. This only pertains to the sprite itself and not any instances where I would draw the sprite manually. Is there a way to set the clipping area to affect all manual drawing of that sprite?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Apr 2013 01:03
I'm not really sure what you mean by drawing the sprite manually.
I could make a bunch of assumptions and just be wrong.
Mind sharing some code with us so we can give some suggestions?
The first thing that comes to mind is that I think you might want to use CloneSprite to lay out your tile map. If you don't want to deal with the multiple sprites after you generate your tile map then you could use GetImage to make a picture of the tile map, attach it to a new sprite, then you only have one sprite for the tile map.

Check out dFenz on Google Play, Windows, or Mac:
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 03:37
When you create a sprite, it's always on screen. Alternatively, you can call drawSprite (the manual way as I call it).

I'm not sure why I'd use clone sprite. I have one single sprite; a large image containing all the different tiles. I cut the image up by creating an animation from it (still a single sprite). I select the different animation frame(image tile), position the sprite, draw it, then move on to the next one.



Hopefully that snippet makes more sense to how I'm currently doing it.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Apr 2013 04:15
Makes sense.
It's not working how I would expect it either.
I'd use clonesprite since AppGameKit can handle a TON of sprites without any issues, I feel more comfortable with that, and I think you have a bit more control. I guess it depends on how many tiles you are making this way. It does seem like a cleaner way to do it.

My results are weird... If I position the sprites at x = 10 I get some cutting off for all but the last draw of the sprite. If I set it to x=20 then no cut offs and all of the sprites draw fine.

I do not see the main sprite on the screen, or if I do it is one of the sprites I've drawn. Maybe try moving it off screen instead of changing its visibility?

I'm attaching my sample to show how I did it.
Hope it helps.

Check out dFenz on Google Play, Windows, or Mac:

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 21st Apr 2013 05:59
I was okayish with your code until the drawViewport function.

Since you only have one sprite, when you call this function it just moves that sprite around. I sort of see how you are trying to use DrawSprite, but, based on the command description, I don't think it is working the way you want.

Command description:
Quote: "
Immediately draws the sprite to the backbuffer at its current position, size, and rotation. This is useful if you want to setup a scene for GetImage to capture. Remember to use ClearScreen to clear any of your own drawing before calling Sync or Render for the actual frame otherwise your drawing may appear twice in the final render."


Basically, after the loops in drawViewport, you should capture the image using GetImage, clear the screen and then re-display it (using a sprite that covers the display and reset it's image to the one from GetImage).

The description specifically says that you should use ClearScreen before the sync or render call to avoid duplications.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Hockeykid
DBPro Tool Maker
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 21st Apr 2013 06:07 Edited at: 21st Apr 2013 06:08
Quote: "I'm using an animation sprite to build a tilemap. I set the frame to the corresponding tile number, then I draw the sprite. No issues here. But, the main sprite itself still draws onto the screen and I don't want that. If I try to hide the sprite, it also hides any instances where I tried to manually draw it. (unlike DB where I can hide a sprite but still paste it) So is there a way to fix this?"


Hide the main sprite, then right before the draw show the main sprite and then right after it hide it again.

Example-Code:



Sean

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Apr 2013 07:03
Quote: "My results are weird... If I position the sprites at x = 10 I get some cutting off for all but the last draw of the sprite. If I set it to x=20 then no cut offs and all of the sprites draw fine."

That is weird, I haven't experienced that.

Quote: "I do not see the main sprite on the screen, or if I do it is one of the sprites I've drawn. "

I didn't at first. The sprite still has the same position and frame from the last tile I drew, and so it's being displayed on top of the last drawn tile. I didn't catch that until I was moving my player sprite around the map and noticed that it goes under the last tile.

Quote: "The description specifically says that you should use ClearScreen before the sync or render call to avoid duplications."

I think that's because it assumes you used getImage and are pasting that image on screen as well, which would appear to make duplicates. But the drawViewport function works perfectly fine.


Thanks HockeyKid, I guess that's the only solution.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 24th Apr 2013 21:30
Quote: "I'm not sure why I'd use clone sprite."

It's clear you're coming from DB , AppGameKit does some things differently.

It saves maintaining your own sprite drawing.

DrawSprite needs to be repeated every frame when the buffer is cleared, AppGameKit looks after the drawing of all the maintained sprites so you don't have to.

Rather than cycling through your map each frame changing the animation frame and drawing the sprite, you can do this process once at the start, but instead of drawing the sprite, clone it.

The end result is you have a shed load of sprites - all in the right place - all with the right frame, but you don't have to redraw any of them.

What's more, since they are sharing the same image - the memory use is negligible - the sprites are just pointers to the image.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Apr 2013 22:00
I agree with Marl, but I'm imagining Phaelax already has something pretty complex set up he's trying to recreate in AGK

www.NaplandGames.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Apr 2013 22:55
And the clones can have different frames set for each one or do they all stay independent? From what you're saying, I'm guessing the only thing a cloned sprite shares is its pointer to the same image and all the parameters are still managed individually?

Is it bad to manage to the drawing manually?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Apr 2013 23:12
I don't think it is necessarily bad other than it seems to be prone to a lot more error as we've seen. The clones have different frames. Everything is independent. When you clone the clone will have the animation frames all set up, the current frame will be the same as the base (so you should change frames after cloning), sizing carries over. I'm not sure about UV offsets.
But all of that can be independently changed on each clone.
dFenz is made of 99% clones.
I've not seen its memory allocation go much of 45meg and there were probably around 75 clones on screen (not a lot, but the images are decent sized since there are a lot of frames).
Also it could be that the video cards are handling the memory for the textures/images.
The game plays well on older android devices (Droid X).
But I do see a dip when I clone about 50 sprites at once on the Droid X, but it is only a few milliseconds (3-5).
All other machines (HTC incredible 2, Nexus 7, Windows, and Mac) I fail to see any lag whatsoever.

I'd love to see a benchmark of the differences if anyone wants to play around with it. It should probably also include various texture sizes and non-power-of-2 sized textures. If ever I get more than 5 minutes breathing room I may do it. It would be nice to have a benchmark program to check devices out too.

www.NaplandGames.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 24th Apr 2013 23:15
My functions are pretty modular in design. It shouldn't be too difficult for me to change my method over to cloned sprites.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Apr 2013 07:02 Edited at: 25th Apr 2013 08:57
My framerates seem to be locked to 60 in AppGameKit, so it's hard to tell if there's any performance gain. Code-wise, I don't think it improves anything, at least not in my specific case. I'm not doing a typical tilemap, and the tiles change constantly and swap between different arrays. It doesn't hurt anything, but what code it saved me in drawing routines, I had to make various loops anyway to update positions anyway.

I attached my current project with two compiled version, one using drawSprite and the other switched to use clone sprite instead. I don't notice any difference, other than my clone code added about 30-40 lines of code. I have 351 cloned sprites

"You're all wrong. You're all idiots." ~Fluffy Rabbit

Attachments

Login to view attachments
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Apr 2013 00:13
Cool Zelda! Thanks! *gets nothing done for the rest of the day*

Well the first time I ran zelda_draw it only used 45mb and zelda_clone used 51... but then I tried running again to confirm and they both use 51mb of memory... Not sure what triggered the difference.

I think Windows can handle a pretty massive amount of clones without any FPS drop. And apparently there's no difference in memory usage between 70 sprites and 350 sprites.

Well... performance benefits = 0, but at least you didn't have to try to figure out what was going wrong with DrawSprite() or work around it.

Thanks for sharing that program for some benchmarking.

www.NaplandGames.com
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 26th Apr 2013 00:47
I'm actually going to continue working on the clone method. Since drawSprite ignores clipping(scissor), this will allow me to not have to put an overlay image on top to hide the extra viewport as it slides in.

As for the extra code, most of the increase was due to a function I left in for drawing that wasn't needed anymore. So really it wasn't much different.

Quote: "Cool Zelda! Thanks! *gets nothing done for the rest of the day*"

I should have all the caves done today.

"You're all wrong. You're all idiots." ~Fluffy Rabbit

Login to post a reply

Server time is: 2024-05-02 07:37:50
Your offset time is: 2024-05-02 07:37:50