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 / Drawing the same sprite multiple times ad different positions?

Author
Message
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 30th Nov 2017 16:32
With object you can create instances which you can position in the scene. This way you only load 1 object and create instances of it, each getting it's own unique ID.

What about things like sprites being used as HUD Displays. I have a generic HUD element used as a sprite and I have multiple places in the view, where I need to display this same sprite.
There will be instances where I need to display 4 sprites and some where I need to display 12, They are all the same sprite and the amount of sprites being displayed varies.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 30th Nov 2017 17:17
you could try CloneSprite(id)
then position them where you need them.
i know they will keep the same animation info but i don't know if it keeps the same active frame or such for animations etc, not actually tried it.
if the sprites are changing each frame then you will need to delete the clones and re-clone in your main loop (as i assume you don't want to update them manually)
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 30th Nov 2017 17:39
I'm going to try and actually use an array that stores IDs of sprites and dynamically create and destroy sprites while expanding and contracting an array (C++ vector). So far this has worked with adding objects.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Nov 2017 19:16
DrawSprite() will do that
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 30th Nov 2017 19:23 Edited at: 30th Nov 2017 19:23
Draw sprite will just draw that particular sprite (by its ID). I need to draw the multiple of the same sprite in different positions though.

Can you do that in a loop?

loop 5 times {
set position
set scale
set image
DrawSprite()
}

?
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Dec 2017 01:23
Yes DrawSprite() will do that. Every time you execute DrawSprite() it will copy that sprite at it's current position and scale to the back buffer. if you do that multiple times, changing scale and position, when you sync you will see multiple copies of the same sprite
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 2nd Dec 2017 01:47
Think of drawsprite() like using a rubber stamp on the back buffer. You are just imposing a one-shot image for that frame only.
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 2nd Dec 2017 02:39
Ok THIS is actually interesting. Thanks for clearing that up.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 5th Dec 2017 02:57
Does anyone have an example of how to make a "trail" of the same sprite using drawsprite?
Tobias_Ripper
11
Years of Service
User Offline
Joined: 24th Mar 2013
Location: REPCONN inc.
Posted: 5th Dec 2017 03:19
I'd think you can make 2 arrays (or one 2 dimensional array) for storing the x and y positions with something like 5 to 10 slots. and have the very first array copy the position of the object sprite while all subsequent array slots would copy the x and y position of the one before it. Then you just make a loop that loops 10 times drawing the sprite at the positions of the array coordinates. Very crude but it'd do the job you're describing. There's really more than one way I see this effect play out and more than one way to code the effect. If you have a concrete reference of the effect you want to use, post it here.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Dec 2017 12:02
Quote: "Does anyone have an example of how to make a "trail" of the same sprite using drawsprite?"


here:
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 6th Dec 2017 08:02
Thank you!

I'm working on something very simple: continuous bullets for a 2D shooter. I've never worked with drawsprite before so I'm still getting used to it.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Dec 2017 09:52
I only use drawsprite if I am building up a composite image for use on another sprite.
Markus
Valued Member
19
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Dec 2017 11:04
@Richard_6
see also SetSpriteImage
AGK (Steam) V2017.09.25 : Windows 10 Pro 64 Bit : AMD (17.11.4) Radeon R7 265 : Mac mini OS High Sierra (10.13)
Phaelax
DBPro Master
20
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Dec 2017 12:14
Quote: "Does anyone have an example of how to make a "trail" of the same sprite using drawsprite?"

I believe the effect you want is called onion skinning.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Dec 2017 13:22
Another option is to use text... get all your sprites onto a fixed grid, make a subimages file, so you can then create a text object with however many 'letters'. The 'letters' on the text object can be coloured and moved and rotated, just like a sprite - but keeping it all as 1 single object, like a dynamic sprite layer if you like.

I've used this to make a tiled 2D map for example... actually a multi layered parallax 2D scrolling map. An old style font in AppGameKit is just a tile sheet with a subimages data file... it can be bent quite a bit to your needs.

It may be a bit of a faff - but what you end up with is a 'layer' of sprites that renders in a single draw call, it renders automatically, and is separate to the general sprite overhead - no need to manage all those sprites - just make changes to the text object instead. It would be absolutely brilliant for a HUD with number displays, even bars, as well as general sprites. Like, you could make a bitmap font for score and displays, then use the free space for other HUD elements - keeping it all as a single image. Doing it with a load of sprites means you have a load of sprites to look after. I like to view text objects as a fridge door - you can throw on magnets to spell a message, but then your magnets don't need to be letters, or in the right order, orientation, position or colour... it all just boils down to an array of vertices at the end of the day - you can add an element by adding a character to the text, then do what you want with that character.
The code is dark and full of errors
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 8th Dec 2017 01:42
I just merged a lot of ideas from this forum and ended up with a simple prototype for my shooter bullets.



Thanks everyone!
Riusz
8
Years of Service
User Offline
Joined: 27th Feb 2016
Location:
Posted: 8th Dec 2017 13:23
Warning : you'll increase nonstop your list so you have to delete the old ones or (better) use a pooling memory management.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 8th Dec 2017 16:25 Edited at: 8th Dec 2017 16:26
This:

Would be better written like this:


Although TBH I'm surprised that you can have a variable with the same name as a type.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 10th Dec 2017 02:11
I got into the habit years ago of naming types as t something.



Yea, I can't believe variables and types of the same name even compiles

Login to post a reply

Server time is: 2024-03-29 10:34:51
Your offset time is: 2024-03-29 10:34:51