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 / level editor place block issues

Author
Message
bszaronos
6
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 12th Jul 2017 18:43
Hello all,

I am trying to make my own editor. I am using sprites that are 88x88. So I created a background grid and loaded it with sprites.
I can move around by pressing the arrow keys and I can even change my image by pressing the a key.
But if I press the space bar, to place my sprite it changes a total of six sprites.

from the images I have my sprite at x=441 and y=265 when I hit space it makes the 6 blocks change.

My code at the bottom in the //place block image is where I am trying to change the images.

Any help, I am pulling out my hair on this.
Thanks

-Brian

Attachments

Login to view attachments
bszaronos
6
Years of Service
User Offline
Joined: 7th Jul 2017
Location:
Posted: 12th Jul 2017 19:53
Well I took a break and went and took a shower, and it came to me.
When I press the key to move I use the underblock to keep track of the spriteID. I start with an spriteID of 1 when I move left I add one to it, Since my grid is 34 blocks long when I press down I add 34 to it.

I know it's not the best code, but its more of figuring out how to do something, then I usually end up finding a better way to do it later on.


29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 12th Jul 2017 20:04 Edited at: 12th Jul 2017 20:08
Hi bszaronos

My initial suspicion is that sprite 502 that is being used to detect collision with the "block" sprites is overlapping multiple sprites, therefore changing all of them.

This bit of code here:

//place block image
If GetRawKeyState(32)
for a=1 to 408
if GetSpriteCollision(a,502) then SetSpriteImage(a,502)
next a

EndIf

Also because you've used GetRawKeyState(), the user, i.e. you, can hold the space key down and move sprite 502 which will result in more collisions being detected and you'll "paint" all the block sprites.

The other thing it might be, is that with all the "sleep" commands, your code might be doing something odd, like detecting a button being held down but not doing anything for a moment. So I'd advise changing where you've got a "RawKeyState" command followed by a sleep command for a "RawKeyPressed" and getting rid of the sleep command.

I'm have to guess a little here as with out all the media I can't run you're code fully (i'm also getting an odd pattern of sprites).

As an example, When I do these kind of things, I tend use the pointer or raw mouse commands, something like this:



Hope this gives you some ideas.

EDIT: I seem to have posted this just as you answered your own question and it also seems that I was wrong, oh well. Glad you sorted it out.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB

Login to post a reply

Server time is: 2024-05-04 22:23:04
Your offset time is: 2024-05-04 22:23:04