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 / Problem with CreateSprite

Author
Message
Djbios76
8
Years of Service
User Offline
Joined: 5th Mar 2016
Location:
Posted: 10th Apr 2017 01:04
Hi guys

I've found a problem with CreateSprite, and checking and excluding piece of code I'm sute that it depends on this function.

I use LoadImage as argument for CreateSprite



when I draw sprite in a position, specified with SetSpritePosition, it's all ok, but there's another instance of the sprite in the top left corner (as you can see in the screen attached)! Any solution?

thanks so much!


Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 10th Apr 2017 02:06
Your for loop is loading the same image/sprite 9 times
Djbios76
8
Years of Service
User Offline
Joined: 5th Mar 2016
Location:
Posted: 10th Apr 2017 10:18 Edited at: 10th Apr 2017 10:40
Hi and thanks for your reply. I know it and I suppose it's not the problem. The loop is loading the same animation for 9 different entities, so it's right. I've discovered that CreateSprite load the sprite in 0, 0 position. I've solved the problem putting a SetSpritePosition with out of windows coordinates just after CreateSprite



in this way I've solved my problem but it's pretty strange and I'd like to know why this happen :/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Apr 2017 11:44
It's normal behaviour. As soon as you create a sprite, it becomes a visible entity at the origin (0,0). You can do what you have done and move it off screen, or SetSpriteVisible to 0.

You should change the way you create your sprites. They can all share the same image instead of loading it 9 times and taking up 9x more memory.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 10th Apr 2017 20:21 Edited at: 10th Apr 2017 20:29
Quote: "You should change the way you create your sprites. They can all share the same image instead of loading it 9 times and taking up 9x more memory."

^ this
Quote: "or SetSpriteVisible to 0"

actually slightly better to make them invisible - when you get lots of sprites you can really tell the difference but for most uses you won't really tell
also if you know a sprite wont have any physics or animation then using SetSpriteActive(sprID,0) helps fps
life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic

Login to post a reply

Server time is: 2024-11-22 15:08:57
Your offset time is: 2024-11-22 15:08:57