Post new topic    
Liquid Metal Slime
Send private message
First attempt with Slices.. I need a bit of guidance. 
 PostWed Nov 06, 2013 7:04 am
Send private message Reply with quote
This evening I decided to buckle down and finally develop a basic understanding of Slices. To do so I made a simple program in which I control an on screen cursor. By left clicking on the mouse, a Slice that I drew from large enemy picture 0 is placed at the mouses (x,y) position. By clicking <and>, I control which large enemy picture is selected to be drawn on screen.

Here's my main questions:

1) How can I make my mouse cursor be replace with the current slice I have selected? (I want to know which slice I'm placing before I place it on screen, I've gotten close but most of my attempts result in the slice image being placed over and over again in a trail as I move the mouse across the screen.)

2) And out of curiosity, how can I make the mouse cursor appear above the Slice images placed on the screen?

Here's my current code so you can get a better idea of where I'm at:

Code:

global variable (0, a)

plotscript, display mouse, begin

   a := 0

  init mouse

  while (true) do(
 
     variable(sl)
   
    put npc (0, mouse pixel x + camera pixel x, mouse pixel y + camera pixel y)
   
    while (mouse click (left button) == true) do(
        sl := load large enemy sprite(a)
   set slice x(sl, mouse pixel x + camera pixel x)
    set slice y(sl, mouse pixel y + camera pixel y)
    wait
    )
    wait
  )
end

plotscript, On Keypress Handler, begin
    if(key is pressed(key:Right Caret)) then(
      a := a + 1
       )
    if(key is pressed(key:Left Caret)) then(
      a := a -- 1
       )
end

⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal Slime
Send private message
 
 PostWed Nov 06, 2013 7:52 am
Send private message Reply with quote
Well, first things first. I see here that you're using an NPC for the mouse cursor. By default, NPCs will be shown underneath other slices, and cannot be changed to show a large enemy sprite. I recommend starting off by using a slice for the mouse cursor.

If you use a slice as your mouse cursor, you can change the cursor image any time with "replace large enemy sprite(slice handle, sprite #)". So here, you'd use "replace large enemy sprite(cursor, a)" whenever the value of a is changed.

When there are a lot of slices, you can use "slice to front(slice handle)" to move the slice you want to the front of the screen.

Just a note, when you create a slice, it starts off attached to the screen rather than to the map. What this mean is, even if you scroll around on the map, the slice will stay at the same spot on your screen. Unless you attach the slice to the map layer, you don't need to add "camerapixelx" or "camerapixely" to its position.


Try something like this, see if this works for you.

Code:
global variable (0, a)
global variable (1, cursor)

plotscript, display mouse, begin
  a := 0

  init mouse
  cursor := loadwalkaboutsprite(###)   # CHANGE THIS: the walkabout sprite of the cursor goes here

  while (true) do(
    put slice (sl, mouse pixel x, mouse pixel y)
   
    if (mouse click (left button) == true) then(
      sl := load large enemy sprite(a)
      set slice x(sl, mouse pixel x)
      set slice y(sl, mouse pixel y)   # Note: these two lines can be replaced with "put slice(sl, mouse pixel x, mouse pixel y)"

      slice to front(cursor)

      while(mouseclick(leftbutton)==true) do(wait)
    )
    wait
  )

end

plotscript, On Keypress Handler, begin
    if(key is pressed(key:Right Caret)) then(
      a := a + 1
    )
    if(key is pressed(key:Left Caret)) then(
      a := a -- 1
    )
    # note that here it is possible for a to go out of bounds. You could end up with negative values, for example.
   
    replace large enemy sprite(cursor, a)
end
Liquid Metal Slime
Send private message
 
 PostWed Nov 06, 2013 3:28 pm
Send private message Reply with quote
RMSephy wrote:

Try something like this, see if this works for you.


Alright I tried your code and it solved most of my problem. Then I started cleaning up the code such that it no longer relies on an NPC as the mouse cursor but instead on a slice which is brought to front. Now the only problem I'm having is when I click "<" or ">" the mouse cursor does not instantly change to the next image. Instead the mouse cursor stays the same until I click once, It places the past image and then the cursor switches to the new image.

Is there a way I can get the mouse cursor image to "refresh" itself as soon as "<" or ">" are clicked?

Here's my new code for reference:

Code:

include, plotscr.hsd
include, scancode.hsi

   global variable (0, a)
    global variable (1, sl)
    
plotscript, display mouse, begin
   a := 0

     #Start up the mouse
   init mouse
      sl := load large enemy sprite(a)
 
   #Loop while the game is running
   while (true) do(
 
        put slice (sl, mouse pixel x + camera pixel x, mouse pixel y + camera pixel y)
   
      if (mouse click (left button) == true) then(
         sl := load large enemy sprite(a)
         put slice (sl, mouse pixel x + camera pixel x, mouse pixel y + camera pixel y)
         slice to front(sl)
   
       while(mouseclick(leftbutton)==true) do(wait)
    )
    wait
  )
end

plotscript, On Keypress Handler, begin
    if(key is pressed(key:Right Caret)) then(
      a := a + 1
       )
    if(key is pressed(key:Left Caret)) then(
      a := a -- 1
       )
end

⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Liquid Metal King Slime
Send private message
 
 PostWed Nov 06, 2013 3:35 pm
Send private message Reply with quote
You removed the line from RMSephy's example that updated the cursor sprite

Code:
replace large enemy sprite(cursor, a)
Liquid Metal Slime
Send private message
 
 PostWed Nov 06, 2013 3:49 pm
Send private message Reply with quote
Bob the Hamster wrote:
You removed the line from RMSephy's example that updated the cursor sprite

Code:
replace large enemy sprite(cursor, a)


That was giving me script error: put slice: invalid slice handle 0, after the error message was skipped the chosen slice would appear in the top left corner of the screen but even then when I clicked to place the slice it would alway place the previous slice first then the current chosen slice upon further clicking.

In the code I just posted I actually decided to no longer use the NPC as a cursor. My new code makes the slice follow the mouse position around the screen and can place slices but will still always place the previous slice before the current one...

Hope that makes sense.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Metal Slime
Send private message
 
 PostWed Nov 06, 2013 3:55 pm
Send private message Reply with quote
That gave an error because in your script you were using 'sl' as the handle for your mouse cursor. So the right script to use here would be

replace large enemy sprite(sl, a)
Liquid Metal Slime
Send private message
 
 PostWed Nov 06, 2013 4:01 pm
Send private message Reply with quote
RMSephy wrote:
That gave an error because in your script you were using 'sl' as the handle for your mouse cursor. So the right script to use here would be

replace large enemy sprite(sl, a)


Thanks, the program performs exactly how I was hoping now.
⊕ P E R S O N A L M U S I C: https://open.spotify.com/album/6fEo3fCm5C3XhtFRflfANr
⍠ C O L L A B M U S I C: https://dustpuppets.bandcamp.com/releases
Display posts from previous: