Need help with character creator.

Blitz3D Forums/Blitz3D Programming/Need help with character creator.

Guy Fawkes(Posted 2009) [#1]
Hi all. I have been studying on how to make a 3d character generator. there are a few problems im having. 1st off, the sword goes BEHIND the brick wall instead of IN FRONT of the wall..which makes it impossible to select a character icon.. the 2nd problem im having is multiplying different character icons and moving each 1 under the 1st 2 selected blocks (see screenshot for more info).

the next problem i cant figure out for the life of me is when i hover over a character icon, as u know, it should brighten up the icon, and when i click the icon, it should STAY brightened and selected.

the blue blocks represent character icons.

the blocks should be in this format:

X X
X X
X X
X X
X X
X X
X X
X X

they should have at LEAST 2 spaces in between each set of blocks.

here's the zip file, and a screenie:

Screenie:



Zip file:

http://www.mediafire.com/download.php?jhl3d5dnfm3

ANY help is GREATLY appreciated! :)

~DS~


GIB3D(Posted 2009) [#2]
This could be an answer to your sword problem. Just draw the sword image last so it will be shown over everything else, code position does matter ;)


Guy Fawkes(Posted 2009) [#3]
wow. hey thanks alot GIA! :)

works like a charm! :)

Now does anybody know how to fix the blocks using the copyimage command to ensure that it copies not once. not twice. but 8 times in a row in sets of 2 as so?

X X
X X
X X
X X
X X
X X
X X
X X

remember the blocks need AT LEAST 2 spaces between each set of 2 blocks :)

and for some reason i cant get the mouse when it clicks a block to ONLY click the block. and nothing else.

ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#4]
If you are using MouseHit, be sure to use it only once every loop.
Repeat
  mh = MouseHit(1)
  if mh then print "clicked"
  if mh then print "still clicked"
Forever

Each time you read mousehit, it resets itself.

And as copyimage is concerned, you can draw the same image multiple times without copying it:



Guy Fawkes(Posted 2009) [#5]
ok. i got this to work.

now the problem is. i need to move the all the blocks over to the left of the screen, so that the 1st block starts at whatever 0, 0 is inside the background image, so no matter what graphics mode im in, the blocks will ALWAYS stay in the background area and i need the block to add "w = w + imagewidth(newim)+64" to EACH block til it reaches the end of the blocks.

also, every 2 blocks, i need to move the 1st block in a set of 2 blocks down where "h = h + imageheight(newim)+64".

Graphics 800, 600, 0, 2
Global im
SetBuffer BackBuffer()
im = LoadImage("button1.png")

While Not KeyHit(1)
For i = 0 To 7
newim=CopyImage(im)
w = w + ImageWidth(newim)+64
DrawImage newim, w, 0
Next
Flip
Wend
End


so the blocks appear like this:

X X
X X
X X
X X
X X
X X
X X
X X

ANY help is GREATLY appreciated! :)

~DS~


Guy Fawkes(Posted 2009) [#6]
there should be a block located in the middle of each "X" in the pic u see below this post:




Warner(Posted 2009) [#7]
While Not KeyHit(1)
For i = 0 To 7
newim=CopyImage(im)
w = w + ImageWidth(newim)+64
DrawImage newim, w, 0
Next
Flip


You shouldn't use CopyImage in that way. A new copy of the image will be made 8 times each loop, resulting in a major memory leak.
Instead, re-use the same image:
While Not KeyHit(1)
For i = 0 To 7
w = w + ImageWidth(im)+64
DrawImage im, w, 0
Next
Flip



Guy Fawkes(Posted 2009) [#8]
ok. now how do i get the blocks to do what i showed in the picture above this & ur post? and how when i mouseover an icon do i get it to brighten up? and when i click it how do i get it to STAY selected?

here's the code

so far:

Graphics 800, 600, 0, 2
Global im
SetBuffer BackBuffer()
im = LoadImage("button1.png")

While Not KeyHit(1)
For i = 0 To 7
w = w + ImageWidth(im)+64
DrawImage im, w, 0
Next
Flip
Wend
End



Warner(Posted 2009) [#9]
Use two For..Next loops, one for X and one for Y:
For x = 0 to 2
for y = 0 to 7
  DrawImage im, x * ImageWidth(im) + 64, y * ImageHeight(im)
Next
Next



Guy Fawkes(Posted 2009) [#10]
thanks! :) works like a charm! :)

now. the problem im having is i cant control the ACTUAL x, y positions of ALL "x" blocks, where x = # of blocks.

i need to have the blocks at the top of the background image, and each block should be INSIDE the background graphic at ALL times :)

and no matter HOW many blocks i put there, the blocks should ALWAYS be at the TOP of the background image and 1 space to the left of the background image is where the 1st block should start :)

code:

Graphics 800, 600, 0, 2
Global background
Global im
SetBuffer BackBuffer()

background = LoadImage("bricktex.jpg")
ResizeImage background, GraphicsWidth()/4-ImageWidth(background)/8, GraphicsHeight()

im = LoadImage("button1.png")

While Not KeyHit(1)
DrawImage background, 0, 0
For x = 0 To 1
For y = 0 To 8
  DrawImage im, GraphicsWidth()/4-4-(x * ImageWidth(im) + 64)*2, GraphicsHeight()-(y * ImageHeight(im) + 64)*2
Next
Next
Flip
Wend
End


ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#11]
Well, first find out the x-position of the blocks. If that works, find out the y-position.
I think first you would need to know the width of the background image.
In this case, that would be:
width = GraphicsWidth()/4-ImageWidth(background)/8

Another idea might be, using MidHandle. That will ensure the images are located around their centerpoint instead of the upper-left corner.
Right after loading the image, use:
MidHandle im

Then you can use 'width' to determine where the images should be placed (on the x-axis). For instance at (width * 3 / 4).


Guy Fawkes(Posted 2009) [#12]
ok. so what did i do wrong here?

i tried to get the pic to stay using midhandle like u said. but it only made things worse. i DID however get the absolute x and absolute y values, i THINK. and PLEASE correct my math if im wrong.

code:
Graphics 3D 800, 600, 0, 2
;Include "../../start.bb"
Global background
Global im
SetBuffer BackBuffer()

background = LoadImage("bricktex.jpg")
ResizeImage background, GraphicsWidth()/4-ImageWidth(background)/8, GraphicsHeight()

im = LoadImage("button1.png")

While Not KeyHit(1)
DrawImage background, 0, 0
For x = 0 To 1
For y = 0 To 8
DrawImage im, GraphicsWidth()/4-4-(x * ImageWidth(im) + 64)*2, GraphicsHeight()-(y * ImageHeight(im) + 64)*2
MidHandle im
Next
Next
;this gets the middle of the screen + the background pic width
tx = GraphicsWidth()/2+StringWidth(GraphicsWidth()/4-ImageWidth(background)/8)
;this gets the middle of the screen + the background pic height
ty = GraphicsHeight()/2+StringHeight(GraphicsHeight()/4-ImageHeight(background)/8)
;this gets the EXACT middle of the background pic PERIOD
string1 = StringWidth(GraphicsWidth()/4-ImageWidth(background)/8)
;this gets the EXACT top of the background pic PERIOD
string2 = StringHeight(GraphicsHeight()/4-ImageHeight(background)/8)

Text tx, ty,"x: "+string1
Text tx,ty+20,"y: "+string2

Flip
Wend
End


ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#13]
As a first step, store the width and height of the background in a variable:
Graphics3D 800, 600, 0, 2
;Include "../../start.bb"
Global background
Global im
SetBuffer BackBuffer()

background = LoadImage("bricktex.jpg")

width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
ResizeImage background, width, height

im = LoadImage("button1.png")
midhandle im

While Not KeyHit(1)
DrawImage background, 0, 0

DrawImage im, width, 0 ;<-this should be placed at top-right side of background

Flip
Wend
End



Guy Fawkes(Posted 2009) [#14]
ok. i tried it. and it made it worse :3

i can barely see blocks.

i tried midhandle, and with / w/o midhandle, it didnt work. :3

code:

Include "../../start.bb"
Global background
Global im
SetBuffer BackBuffer()

background = LoadImage("bricktex.jpg")

width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
ResizeImage background, width, height

im = LoadImage("button1.png")
MidHandle im

While Not KeyHit(1)
DrawImage background, 0, 0

DrawImage im, width, 0 ;<-this should be placed at top-right side of background
MidHandle im

Flip
Wend
End


ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#15]
You only need to call MidHandle once. After that, the image is allways midhandled. So remove the second Midhandle from the code above.
What do you mean with barely seeing any blocks? If all went well, there is only one block drawn.
Try changing the width/height calculation in the above code to this:
width = GraphicsWidth() / 3
height = GraphicsHeight()


Guy Fawkes(Posted 2009) [#16]
This works. but the problem is. the background is too big. and the images are too close together.

Include "../../start.bb"
Global background
Global im
SetBuffer BackBuffer()

background = LoadImage("bricktex.jpg")

width = GraphicsWidth()/3
height = GraphicsHeight()
ResizeImage background, width, height

im = LoadImage("button1.png")
MidHandle im

While Not KeyHit(1)
DrawImage background, 0, 0
For x = 0 To 1
For y = 0 To 7
  DrawImage im, width/2-(x * ImageWidth(im) + 64)+12, y * ImageHeight(im) + 64
Next
Next
Flip
Wend
End


It needs to put the block in the SAME place that the top-left corner of the image starts.

ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#17]
Then change it to something else, such as GraphicsWidth() / 4.
And the top-left corner, isn't that just 0, 0?


Guy Fawkes(Posted 2009) [#18]
no. because i need it to be INSIDE the image. thats why i need the absolute x & y coordinates.


Warner(Posted 2009) [#19]
Then it is a certain percentage times the width and height.
Ie: 0.25 * width, 0.25 * height.
You can calculate this percentage from the original image:
x / original_width, y / original_height
Say, on the original image, you want to draw a tile at (40, 30)
And the original width/height is (400, 300)
Then:
x is 40 / 400 = 0.1
y is 30 / 300 = 0.1
Calculate this yourself, there is no need to put this into the program.

In your program, draw your image with these percentages:
DrawImage im, 0.1 * width, 0.1 * height

The same goes for the distance between the tiles. It can also be calculated from the original image's properties.
Say, in the original image, the distance between two tiles is 80 pixels.
Then:
distance is 80 /400 = 0.2

In your program, draw your image like this:
For x = 0 to 2
DrawImage im, (0.1 * width) + (0.2 * width * x), 0.1 * height
Next

Where (0.1 * width) is the offset (where it starts on the left)
and (0.2 * width * x) takes care of the distance between each tile


Guy Fawkes(Posted 2009) [#20]
works perfect now!

i tweaked it!

ok. theres only 5 problems left. then this is solved! :)

now the next problem is when i mouse over the icons ONLY, it should highlight it. how do i do that?

also. when i click an icon it should select it, highlight, and STAY selected and highlighted. how do i do this?

the next problem is, i have this data, and need to know EXACTLY how to keep the mouse IN ALL 4 sides of the screen. i do NOT want my mouse being able to escape the screen.

code:

Function MouseUpdate()
	Local b.mousebutton
	

	mouse\speedz=MouseZSpeed()
	mouse\speedx=MouseXSpeed()
	mouse\speedy=MouseYSpeed()
	If mouse\controlled Then
		mouse\x=mouse\x+mouse\speedx
		mouse\y=mouse\y+mouse\speedy
If MouseY() >= 0 Then MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
If MouseX() > GraphicsWidth() Then MoveMouse GraphicsWidth()/2,GraphicsHeight()/2


characreate code:

;Include "../../start.bb"
Include "mouseinclude.bb"

Global gfxw,gfxh,gfxd,gfxmode

HidePointer

gfxw=800
gfxh=600
gfxd=0
gfxmode=2

setgfx3d(gfxw,gfxh,gfxd,gfxmode)
Global background
Global im
SetBuffer BackBuffer()

im = LoadImage("button1.png")
MidHandle im

background = LoadImage("bricktex.jpg")
mouseicon = LoadImage("sword.png")

If gfxw = 1600
imwidth = 64
imheight = 64
Else If gfxw = 1152
imwidth = 44
imheight = 44
Else If gfxw = 400
width = GraphicsWidth()/2-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
Else If gfxw = 800
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
Else
imwidth = 32
imheight = 32
EndIf

ResizeImage im, imwidth, imheight
ResizeImage background, width, height

mouse\controlled=1

While Not KeyHit(1)

mouseupdate

Cls

origx# = 0
origy# = 0
DrawImage background, origx#, origy#
For x = 0 To 1
For y = 0 To 7
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), 0.2 * height + origy#
Next
Next
DrawImage mouseicon, mouse\x, mouse\y
UpdateWorld
RenderWorld
Flip
Wend

Function setgfx3d(w=800, h=600, d=0, mode=2)

Graphics3D w, h, d, mode

End Function


just the "If MouseX()" and "If MouseY()" code should be changed. do with it what u wish.

the next problem is when u select an icon, it should play a select sound.

and finally. for some reason, im only seeing "2" blocks. not "8".

ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#21]
for some reason, im only seeing "2" blocks. not "8".
Well, first solve that problem. There are two loops allready. 0 to 1 and 0 to 7.
That means that it does draw 16 images. Think about why you only see 2.


Guy Fawkes(Posted 2009) [#22]
to be honest, i have no idea.. is it because of the y value?


Guy Fawkes(Posted 2009) [#23]
ok. so i fixed that part. but how do i like highlight the icon when moused over and when i click the icon, how do i make it highlight and stay highlighted, select and stay selected?
how do i make it so that each block is clickable?

code:

Include "../../start.bb"
Include "mouseinclude.bb"

Global origx# = 0
Global origy# = 0

Global HWND=SystemProperty("AppHWND")
Global HWND_TOP = 3

Global gfxw,gfxh,gfxd,gfxmode,maxblocks
maxblocks = 7

HidePointer

gfxw=1024
gfxh=768
gfxd=32
gfxmode=1

;setgfx3d(gfxw,gfxh,gfxd,gfxmode)
Global background
Global im
SetBuffer BackBuffer()

im = LoadImage("button1.png")
MidHandle im

background = LoadImage("bricktex.jpg")
mouseicon = LoadImage("sword.png")

If gfxw = 1600
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()/1.5
imwidth = 44
imheight = 44
ResizeImage background, width, height
If gfxmode = 2 Then api_movewindow(HWND, 0, 0, GraphicsWidth(), GraphicsHeight(), $000A)
Else If gfxw = 1280 And gfxh = 960
imwidth = 64
imheight = 64
ResizeImage im, imwidth, imheight
Else If gfxw = 1152
imwidth = 44
imheight = 44
ResizeImage im, imwidth, imheight
Else If gfxw = 1024
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 720
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 44
imheight = 44
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 400
width = GraphicsWidth()/2-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else If gfxw = 800
width = GraphicsWidth()/4-ImageWidth(background)/8
height = GraphicsHeight()
imwidth = 32
imheight = 32
ResizeImage background, width, height
ResizeImage im, imwidth, imheight
Else
imwidth = 32
imheight = 32
ResizeImage im, imwidth, imheight
EndIf

mouse\controlled=1

While Not KeyHit(1)

mouseupdate

Cls

DrawImage background, origx#, origy#
For x = 0 To 1
For y = 0 To maxblocks
If gfxw = 1600
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)-8
Else
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)
EndIf
Next
Next
DrawImage mouseicon, mouse\x, mouse\y
UpdateWorld
RenderWorld
Flip
Wend

Function setgfx3d(w=800, h=600, d=0, mode=2)

Graphics3D w, h, d, mode

End Function


ANY help is GREATLY appreciated! :)

~DS~


Warner(Posted 2009) [#24]
Well, first question is, how do you highlight images? Do you draw a rectangle around it, or do you draw another image in it's place? Or do you want to blink it?

Assuming you want to use another image for highlighting. This other image should be loaded, and it should be called "im2":
im2 = LoadImage("button2.png")
Midhandle im2


The original image should be renamed to "im1", but only in the part that loads it, and not in the For..Next loop that draws it.
im1 = LoadImage("button1.png")
Midhandle im1


At this point, there are two images loaded. Their handles are stored in im1 and im2. "im" is empty.
If you would try to run the program now, it would give an error on
DrawImage im, ..etc
Because there is no image in "im".
However, if you put:
im = im1

Then "im" does contain an image.

So put this line (above) in, pref. somewhere before the DrawImage instruction, and see what it does. It should draw the first image everywhere.
Then, change it to this:
im = im2

Now, it draws the second image everywhere.

So now, it is a matter of finding out what image the mouse is over, and highlighting that image:
If (mouse is over this image) Then im = im2 Else im = im1
DrawImage im, .. etc



Guy Fawkes(Posted 2009) [#25]
right. how do u get the mouse to know when ur mousing over an image?

like what would i use?

if mousex() > width? idk..

~DS~


Warner(Posted 2009) [#26]
yea I guess that would be it, if (x > left) and (x < right) and (y > top) and (y < bottom), or this:
If rectsoverlap(mousex(),mousey(),1,1, imageleft,imagetop,imagewidth,imageheight) Then ..


Guy Fawkes(Posted 2009) [#27]
heres what i have so far:

If RectsOverlap(mouse\x,mouse\y,1,1, imageleft,imagetop,ImageWidth,ImageHeight)


how would i get the value of 1, 1, imageleft, and imagetop?


Warner(Posted 2009) [#28]
(1,1) is one pixel, that would be the size of the mouse pointer.
Scratch that idea, it might be more easy to use:

If ImageRectOverlap(im, x, y, mousex(),mousey(),1,1)

Where x, y are the position that you drew the image on with DrawImage.
Just copy-paste them from the DrawImage line into ImageRectOverlap:
DrawImage im, <this is x>, <this is y>


Guy Fawkes(Posted 2009) [#29]
works great. except for 1 thing. i need it to be the bottom-left corner of the sword picture. i used this pic and changed my mouse icon.

so i need it to get the width and height of the sword, instead of the mouse width and height, as it activates what i have under "if rectsoverlap()" before it should, and 1 pixel to the right of where it should be. and 1 pixel to the bottom of where it should be.

I is 1 coordinate too far where i move my mouse to.

I should be where X is.

XI XI
XI XI
XI XI
XI XI
XI XI
XI XI
XI XI
XI XI

other than that, it's perfect! :)


Guy Fawkes(Posted 2009) [#30]
here's what i have:

and 2 more things.

i can only select the left side row of blocks if i use:

If MouseHit(1)
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),1,1)
Wb3d_Notify "","",0
Endif
Endif


HidePointer

MoveMouse GraphicsWidth()/2, GraphicsHeight()/2

For x = 0 To 1
For y = 0 To maxblocks
If MouseHit(1)
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),1,1)
WB3D_Notify "","",0
EndIf
EndIf
Next
Next

DrawImage background, origx#, origy#
For x = 0 To 1
For y = 0 To maxblocks
If gfxw = 1600
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)-8
Else
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)
EndIf
Next
Next
DrawImage mouseicon, MouseX(), MouseY()


and why am i not seeing my mousepointer in 1024,768,0,1 mode or ANY mode in fullscreen for that matter, when i put a " ; " next to hidepointer? :S

~DS~


Guy Fawkes(Posted 2009) [#31]
nvm. i solved the 8 block click error. :)

now the only 2 problems are being able to click the block while hiding the mouse, and using a graphic instead, and fixing the mouse so i can see it in any full screen mode :)


Guy Fawkes(Posted 2009) [#32]
u know what i mean, right warner?


Warner(Posted 2009) [#33]
That's nice. HidePointer should only be placed at the start of the program. After it is called, the pointer stays hidden until ShowPointer is called.
I'm not sure what you mean, but looking at MoveMouse and HidePointer, I think of the following:



Guy Fawkes(Posted 2009) [#34]
"now the only 2 problems are being able to click the block while hiding the mouse, and using a graphic for the mouse instead, and fixing the mouse so i can see it in any full screen mode :)"


Guy Fawkes(Posted 2009) [#35]
the problem im having is the mouse shows up fine in windowed mode. its just fullscreen that it disappears in. and i need to be able to detect the coords of imagesrectoverlap or w/e of the mouse when an image is applied to it, and the mouse is hidden. not the mouse itself man :)


Guy Fawkes(Posted 2009) [#36]
did i explain well enough this time?


Warner(Posted 2009) [#37]
In fullscreen mode, the cursor is indeed hidden. Not sure if you can bring it back with ShowPointer? But in your code, there is allready this:
DrawImage mouseicon, MouseX(), MouseY()

That should take care of it?


edit:
Make sure to remove this line from your code
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
Otherwise the mouse will be fixed in the center of the screen.


Guy Fawkes(Posted 2009) [#38]
ok. then what about this? i need to be able to detect the coords of imagesrectoverlap or w/e of the mouse when an image is applied to it, and the mouse is hidden. not the mouse itself


Warner(Posted 2009) [#39]
Do you mean you need to find out which image you are overlapping? At the time that RectsOverlap (o.s.) is true, you have a valid x and y value.
That should give the information which image you are hovering:
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),1,1)
runtimeerror x + "," + y
EndIf

Also, MouseHit() can only be read once. After that it resets itself.
So before entering the For..Next loops, store MouseHit in a variable, and use that variable to check
mh = MouseHit(1)
For x = .. etc
For y = ..
If mh then .. etc



Guy Fawkes(Posted 2009) [#40]
ahh. that improves the code. but what i need is like to be able to use ANY image on the mouse, while still being able to click anywhere ON OR inside the image. :) so instead of the mouse coords, correct me if im wrong, i would need to find the coords of the image which is being used by the mouse? :3


Guy Fawkes(Posted 2009) [#41]
also. im having a small problem with this.

code:

For x = 0 To 1
For y = 0 To maxblocks
If mh
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),x,y)
FreeEntity player1
meshgone = 1
which = y
EndIf
EndIf
Next
Next

if meshgone = 1
loadmodel(which)
endif

function loadmodel(which)
If which = 0 Then player1=LoadAnimMesh("markio/mariorun.x")
If which = 1 Then player1=LoadAnimMesh("media/ninja.b3d")
return which
end function

DrawImage background, origx#, origy#
For x = 0 To 1
For y = 0 To maxblocks
If gfxw = 1600
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)-8
Else
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)
EndIf
Next
Next
DrawImage mouseicon, MouseX(), MouseY()


what i need is to be able to click on a block, and give that block an id. using that id, if theres already a model there, i would like to delete that model, and reload a new model depending on which image i selected.

~DS~


Warner(Posted 2009) [#42]
But the image that is used by the mouse is drawn here:
DrawImage mouseicon, MouseX(), MouseY()
So it's coords would be MouseX(), MouseY(), right ?

To get an ID, use x and y combined.
Ie:
id = y * 2 + x


Guy Fawkes(Posted 2009) [#43]
well yes. but when i use "drawimage mouseicon, mx, my"
the coordinates for "If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),1,1)" get screwed up.

i cant use the end of the sword to select the image..

it is still trying to get the mouse coordinates for imagerectoverlap(). not the coordinates of "mx, my" which are mx = mousespeedx() and my = mousespeedy().

here's the new data:

mx = mx + MouseXSpeed()
	my = my + MouseYSpeed()
;MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
	
	If mx < 0 Then mx = 0
	If my < 0 Then my = 0
	If mx > GraphicsWidth() Then mx = GraphicsWidth()
	If my > GraphicsHeight() Then my = GraphicsHeight()


mh = MouseHit(1)

If mh
For x = 0 To 1
For y = 0 To maxblocks
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), MouseX(),MouseY(),1,1)
WB3D_Notify "","",0
;FreeEntity player1
;meshgone = 1
;which = 1
;If which = 1 Then player1=LoadAnimMesh("markio/mariorun.x")
EndIf
Next
Next
EndIf

DrawImage background, origx#, origy#
For x = 0 To 1
For y = 0 To maxblocks
If gfxw = 1600
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)-8
Else
DrawImage im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#)
EndIf
Next
Next
DrawImage mouseicon, MouseX(), MouseY()


~DS~


Warner(Posted 2009) [#44]
Then instead of MouseX(), MouseY(), use mx, my


Guy Fawkes(Posted 2009) [#45]
i tried that. x)

didnt work..

here's the zip file if u wanna look, i have tried EVERYTHING so far, and it didnt work. x)

just put user32.decls inside the userlib folder.

if u help me fix the clicking on the images, and the loading of different models dependant on ids, i will SO owe u.

here's the zip file:

[EDIT]: Image removed. Problem SOLVED thanks goes to Warner! :)

thanks again man :)

if theres ANYTHING u need, just let me know. and ill do my best to get it for ya :)

~DS~


Warner(Posted 2009) [#46]
The reason it doesn't work properly, is because the point at the sword is at (0, 44) and not at (0, 0). It works, but only for the upperleft corner of the sword image. Since that corner is transparent, it looks like it works wrong.
Try this:
HandleImage mouseicon, 0, 44

After ResizeImage mouseicon, 44, 44


Guy Fawkes(Posted 2009) [#47]
AWESOME warner! thanks! :)

1 small thing still troubles me..

in this data below:

If mh
For x = 0 To 1
For y = 0 To maxblocks
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), mx,my,1,1)
FreeEntity player1
which = y
loadmodel(which)
EndIf
Next
Next
EndIf

Function loadmodel(which)
If which = 0 Then player1=LoadAnimMesh("markio/mariorun.x")
If which = 1 Then player1=LoadAnimMesh("media/ninja.b3d")
Return player1
End Function


i cant get when i click on a block, for it to delete the 1st model, and load the 2nd model.

what am i doing wrong?

other than that, its PERFECT! :)

~DS~


Warner(Posted 2009) [#48]
Maybe player1=loadmodel(which) ?


Guy Fawkes(Posted 2009) [#49]
OMG! IT WORKS! THANK YOU SO MUCH MAN! :D

just for the record, how can i get like block 1 to = 0 as an id, block 2 to = 1, and so on til i reach 16 which = 15?

thanks! :)

~DS~


Guy Fawkes(Posted 2009) [#50]
also, how do i highlight the icon? using a rect?

here is the data:

If mh
For x = 0 To 1
For y = 0 To maxblocks
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), mx,my,1,1)
Color 255,255,255
Rect (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), ImageWidth(im), ImageHeight(im), 0
FreeEntity player1
which = y
player1 = loadmodel(which)
EndIf
Next
Next
EndIf


i tried the above. but it didnt work.

i need it when you mouse over an icon that it highlights.

and if u click on an icon, it highlights :)

~DS~


Warner(Posted 2009) [#51]
I'm glad it works. Nice work! For explaination how to highlight the icons, look here:
http://www.blitzmax.com/Community/posts.php?topic=85549#968530
But first I would recommend to solve the 'id' issue.


Guy Fawkes(Posted 2009) [#52]
and how would i go about doing that? :3


Warner(Posted 2009) [#53]
Now you are basically doing this:
id = y

In order to get items from 0..15, use x as well.


Guy Fawkes(Posted 2009) [#54]
AMAZING! U ARE SIMPLY AMAZING! y * 2 + x DID IT! :D

now the ONLY thing left is to highlight the icon w/ a rect OR image depending on what u want. (u can choose either or), both when you mouse over, and it STAYS highlighted ONLY if u click on the icon :)

Thanks! :)

~DS~


Guy Fawkes(Posted 2009) [#55]
also, how would i detect if say a default player has been loaded, and u are trying to select that same character icon?

player1 = loadmodel(which)
newid = ?


Function loadmodel(which)
If which = 0 Then player1=LoadAnimMesh("media/ninja.b3d") : ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
If which = 1 Then player1=LoadAnimMesh("markio/mariorun.x") : ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
MessageBox(SystemProperty("ApphWnd"), player1, newid, 0)
If player1 = newid
HidePointer
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
MessageBox(SystemProperty("ApphWnd"), "This player has already been chosen!", "Warning!", 0)
EndIf
Return player1
End Function



Warner(Posted 2009) [#56]
Store the previous id, and compare the new id with it.
Same goes for highlighting: store the number of the icon that is highlighting and keep it highlighted. But first make it so that it highlights if mouse goes over it.

if (mouse_over_icon) then selected = image_id
if (image_id = selected) then highlight_this_image


Guy Fawkes(Posted 2009) [#57]
ok. small problem. the rect wont show up at the right place man..

here's a pic:



and here's the code:

mh = MouseHit(1)

If mh
For x = 0 To 1
For y = 0 To maxblocks
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), mx,my,1,1)
which = y * 2 + x
If player1 <> 0
FreeEntity player1
player1 = loadmodel(which)
newid = player1
EndIf
EndIf
Next
Next
EndIf

DrawImage background, origx#, origy#

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy, mx,my,1,1)
Color 255,255,255
Rect imx, imy, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next


the line you wanna check, is imx, imy

~DS~


Warner(Posted 2009) [#58]
That is because the rectangle is drawn from the center point of the image. (imx, imy)


Guy Fawkes(Posted 2009) [#59]
so what would it be? imgx/2?


GIB3D(Posted 2009) [#60]
Just subtract how big the rectangle is, divided by 2, from the coordinates.


Guy Fawkes(Posted 2009) [#61]
thanks gia! works great! :)

only 1 problem. how for each image, do i load a different image? like i have an icon of a warrior where which = 0, and an icon of a mage where which = 1. etc..


Guy Fawkes(Posted 2009) [#62]
did i explain good enough?

also, how when i click an icon do i make it STAY highlighted, And if i choose another icon how do i UNhighlight the 1st icon and keep the 2nd 1 highlighted?


Guy Fawkes(Posted 2009) [#63]
can someone plz tell me? i learn by example.


Warner(Posted 2009) [#64]
Store which image is selected in a variable, like this:
if (mouse_over_icon) then selected = image_id
if (image_id = selected) then highlight_this_image 

For using multiple images, try looking at imagestrips. They can be loaded with LoadAnimImage rather than LoadImage.


Guy Fawkes(Posted 2009) [#65]
so.....

i do this?

ninja = loadimage("ninja.png")
mage = loadimage("mage.png")

if which = 0 then...

crap.. im lost..


Warner(Posted 2009) [#66]
Imagestrip=big image that is built from smaller images next to each other.

allicons = LoadAnimImage("imagestrip", 32, 32, 0, 7) ;<----image contains 7 images all sized 32x32.

DrawImage allicons, 0, 0, which ;<----last parameter=which image


Guy Fawkes(Posted 2009) [#67]
true. but if i multiply that. that will take 7 of the ENTIRE film strip images, and multiply it by 16, and make it 16*7 images :S

i need to use 1 image for each block image, using the for..loop..


Warner(Posted 2009) [#68]
Not really, if you need 7 possible images for all buttons, your imagestrip needs only 7 images in it.


Guy Fawkes(Posted 2009) [#69]
right. but what im saying is. wont:

for x = 0 to 1
for y = 0 to 7
drawimage blah...
next
next

repeat the film strip image?


Warner(Posted 2009) [#70]
No it just draws only one of the images in the strip. The optional parameter of DrawImage will let you choose which one it should draw. That is the idea of an imagestrip. It is really convenient for these situations.


Guy Fawkes(Posted 2009) [#71]
ahh. ok. well. lemme try it. i will tell u if it works man

:)


Guy Fawkes(Posted 2009) [#72]
right ok. it didnt work.

here is the code:

global maxblocks = 8

im = LoadAnimImage("filmstrip.png", 32, 32, 0, 2)
MidHandle im

while not keyhit(1)
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If gfxw = 1600
DrawImage im, imx, imy-8, y
Else
DrawImage im, imx, imy, 1
EndIf
Next
Next
updateworld
renderworld
flip
wend


my image is 64x32.

my image contains a color-inverted red block, and the original blue block. :)

it works. the problem is. i can only select between 1 frame OR the other. not using ALL frames at once, and 1 image for each block.


Warner(Posted 2009) [#73]
Try this:
DrawImage im, imx, imy-8, Rand(0, 1)
Else
DrawImage im, imx, imy, Rand(0, 1)



Guy Fawkes(Posted 2009) [#74]
so how would i place a different image for each block?

here's the blocks:

X X
X X
X X
X X
X X
X X
X X
X X

and here's the image:

image1 image2
image3 image4
image5 image6
image7 image8
image9 image10
image11 image12
image13 image14
image15 image16.

:)


Guy Fawkes(Posted 2009) [#75]
HOLY HELL! IT KEPT RANDOMIZING THEM! O.O

They kept randomizing for each block.

so what am i doing wrong?


Warner(Posted 2009) [#76]
Well, you have calculated image_id, right? That is a number that goes from 0 to 15 for each image. So if you insert that number into DrawImage it should draw the images as you describe. Offcourse, you'll need to load 16 images inside your test imagestrip. Else you might get an error.


Guy Fawkes(Posted 2009) [#77]
also, the coordinates are a little off as the image is 64 x 32.

how do i fix that?


Warner(Posted 2009) [#78]
Crosspost - nothing wrong. Using Rand() will ensure random values. It was to demonstrate that this parameter determines what image you want to draw at that location.


Guy Fawkes(Posted 2009) [#79]
no. what im saying is, rand made it flash from red to blue on each block. not put a different image on each block.


Warner(Posted 2009) [#80]
I know, I was saying that was intentionally to demonstrate that this parameter determines what image you want to draw at that location. Different number=different picture. So trick is now, to find the right number. That number is the same number as the image_id. You know, y * 2 + x .. So enter this number where now Rand() is, and it should work... as long as the imagestrip also contains 16 images.


Guy Fawkes(Posted 2009) [#81]
nope. image frame out of range.


Warner(Posted 2009) [#82]
That means you are trying for example to draw image no 17 when you only loaded 16 images from the imagestrip.


Guy Fawkes(Posted 2009) [#83]
never mind.

i changed maxblocks to 0 and that did it.

cuz maxblocks = 0 is actually 2 blocks :)

thanks alot, warner! :)

now the VERY LAST thing left is. how EXACTLY do i detect if a player has ALREADY been loaded.

code:

mh = MouseHit(1)

If mh
For x = 0 To 1
For y = 0 To maxblocks
If ImageRectOverlap(im, (0.2 * width) + (0.57 * width * x) + (origx#), (0.2 * height) + (0.1 * height * y) + (origy#), mx,my,1,1)
which = y * 2 + x
If player1 <> 0
FreeEntity player1
player1 = loadmodel(which)
newid = player1
EndIf
EndIf
Next
Next
EndIf


:)


Warner(Posted 2009) [#84]
Store 'which' in another variable when you are using loadmodel.
Then, next time you load, compare this other variable with the new 'which'.

if which <> oldwhich then
player1 = loadmodel(which)
oldwhich = which
end if


Guy Fawkes(Posted 2009) [#85]
ok. whats wrong w/ this?

i tried to fix my if, and messed it up.

can u plz tell me how to fix it so it detects if a player is already loaded?

im close, i just know it..

code:

If mh
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy,mx,my,1,1)
;oldfwhich = y * 2 + x
selected = oldwhich
FreeEntity player1
If which = oldwhich Then
player1 = loadmodel(oldwhich)
Else
MessageBox(SystemProperty("ApphWnd"), "Warning!", "Already chosen!", 0)
EndIf
If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
EndIf
Next
Next
EndIf


thanks!

~DS~


Warner(Posted 2009) [#86]
Just go by it line by line:
;oldfwhich = y * 2 + x <-- why is this line commented out? there is a typo
selected = oldwhich <--where does oldwhich come from? it has no value
FreeEntity player1
If which = oldwhich Then <--where does which come from? it has no value
player1 = loadmodel(oldwhich) <--oldwhich still has no value

-->which still has no value
If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
EndIf



Guy Fawkes(Posted 2009) [#87]
ok, now its working for the 1st player box. but when i load the 2nd player, and select the 2nd player box, it wont error message.

it will still load it..

also, i cant get my characreate to = 1 if the mouse is not on 1 of the blocks.. so that i may use my mouse to rotate my player's y-axis..

code:

If characreate = 0
If player1 <> 0
If MouseDown(1)
TurnEntity player1, 0, -MouseXSpeed(), 0
EndIf
EndIf
EndIf

If mh
oldwhich = 0
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy,mx,my,1,1)
which = y * 2 + x
selected = which
If player1 <> 0 And which <> oldwhich Then FreeEntity player1
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
ShowPointer
MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
HidePointer
If which <> oldwhich Then
player1 = loadmodel(which)
If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
oldwhich = which
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
ShowPointer
MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
HidePointer
Else
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
ShowPointer
MessageBox(SystemProperty("ApphWnd"), "Already chosen!","Warning!", 0)
HidePointer
EndIf
EndIf
Next
Next
EndIf



Flemmonk(Posted 2009) [#88]
Maybe if you format your code with Tabs you will understand it better?


Guy Fawkes(Posted 2009) [#89]
no.... i wish u select few people would realize i code the way i code because its easier for me -.-


Guy Fawkes(Posted 2009) [#90]
i know u tryin to help. and i appreciate it, but i already know what im doing, its just sometimes i get stuck in a root. and i need a bit of help. thats all.


Guy Fawkes(Posted 2009) [#91]
sorry if i sounded alarming.

that wasnt my intention.


Guy Fawkes(Posted 2009) [#92]
now. does anybody know what i did wrong?


Ross C(Posted 2009) [#93]
I think the point about tabbing, is mainly so others can help. It can be very difficult to spot loops and if end if statements with no tabbing, or where a particular loop starts:

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, -MouseXSpeed(), 0
		EndIf
	EndIf
EndIf

If mh
	oldwhich = 0
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
				ShowPointer
				MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
				HidePointer
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
					HidePointer
				Else
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf


That makes it a hell of alot easier to see whats happening.


Guy Fawkes(Posted 2009) [#94]
ok then. so i dont know how to do it. so what?

what do i do?

press alt 4 times, then 8 times, then 12 times then 16 times?

or what?


Ross C(Posted 2009) [#95]
You pressing the tab key after you have started a loop, or an if statement. Any piece of code that is going to be part of a block:


for loop = 0 to 10
   blah
next



Like that. Tab the entire loop in. The same with any type or loop. The entire loop contents should be tabbed in. If there is any loops inside the loop, tabb them in once more. The same with IF statements:


If x = 0 then
   blah
   for loop = 0 to 10
      blah
   next
end if



This way you can see easily where a loop starts and end. And you can see what action is taken from an if statement more easily. I also TAB type declaration:

Type House
   Field name
   Field doors
End type



Guy Fawkes(Posted 2009) [#96]
ah. ok. i always wondered how to do that.


Guy Fawkes(Posted 2009) [#97]
warner, here's the code in format:

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, -MouseXSpeed(), 0
		EndIf
	EndIf
EndIf

If mh
	oldwhich = 0
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
				ShowPointer
				MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
				HidePointer
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "which:"+which,"oldwhich:"+oldwhich, 0)
					HidePointer
				Else
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf


i need to know what im doing wrong here. when i choose the same character, it works the 1st time, but when i select another character, it does the same thing. also, i cant get "selected" to be 1 ONLY when ur mouse is on a block. this should have worked..


Warner(Posted 2009) [#98]
Why are you resetting oldwhich to zero at the start of this routine?
That makes it 'forget' which shape was selected before.


Guy Fawkes(Posted 2009) [#99]
then what should oldwhich be? X_X


Warner(Posted 2009) [#100]
Try removing the line oldwhich=0?


Guy Fawkes(Posted 2009) [#101]
nvm. fixed. theres only 2 problems. how do i get the rect to STAY IF SELECTED, and when changing to a different character, remove the 1st rect, and change it to the box i chose?

code:

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

If selected
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy, mx,my,1,1)
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
Else
characreate = 0
EndIf
Next
Next



Guy Fawkes(Posted 2009) [#102]
i hope i explained well enough.. X_X


Guy Fawkes(Posted 2009) [#103]
it still doesnt work..

i need to be able to select a block. and when i select the block, the rect should STAY ON that block, til i choose another block. in which case it should remove itself, and move to the 2nd block :)

and the final glitch of the entire thing:

when i choose another character, my character STILL turns when i have the mouse down.. it should ONLY activate mouse IF characreate = 0.. :)

and i give u the VERY LAST 2 final glitches:

code revision:

;-------------------------------------------------------------------
;Chara Create - Version 1.0
;This header must remain INTACT at ALL times...
;---------------------------------------------------------------
;Created by: ~DarkShadowWing~ of: http://blitzbasic.com
;============================================================
;You may NOT steal this code and use it for your own personal usage without the authors written permission
;Any chance of doing so will automatically result in a copyright infringement...
;If you remove this header, you will be prosecuted to the fullest extent of the law...
;============================================================
;------------------------------------------------------------------- 

old_mouse_x = cur_mouse_x 
cur_mouse_x = MouseX() Shr 1
mouse_x_delta = cur_mouse_x-old_mouse_x
characreate = newchar
newchar = 0
newfinal = newchar
oldselect = newselect
newselect = 0
newsfinal = newselect

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

If characreate = 0 And newselect = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next


~DS~


Warner(Posted 2009) [#104]
In the second For..Next loops, again calculate 'which'.
which = 2 * y + x
Then, instead of this:
If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
use
If (which = selected)


Guy Fawkes(Posted 2009) [#105]
um, yea. still wont work..

code:

;-------------------------------------------------------------------
;Chara Create - Version 1.0
;This header must remain INTACT at ALL times...
;---------------------------------------------------------------
;Created by: ~DarkShadowWing~ of: http://blitzbasic.com
;============================================================
;You may NOT steal this code and use it for your own personal usage without the authors written permission
;Any chance of doing so will automatically result in a copyright infringement...
;If you remove this header, you will be prosecuted to the fullest extent of the law...
;============================================================
;------------------------------------------------------------------- 

old_mouse_x = cur_mouse_x 
cur_mouse_x = MouseX() Shr 1
mouse_x_delta = cur_mouse_x-old_mouse_x
characreate = newchar
newchar = 0
newfinal = newchar
oldselect = newselect
newselect = 0
newsfinal = newselect

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

If characreate = 0 And newselect = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
which = 2 * y + x
If (which = selected)
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next


i changed the 2nd line as u told me to do so.

also, i still cant get the rect to STAY ON the block when i click it, and when i select another block, delete the 1st rect, and move it to the 2nd block.

~DS~


Warner(Posted 2009) [#106]
Ah, yes, but there are 2 sets of code that draw rectangles, so you have to remove this one:
If characreate = 0 And newselect = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf

It is in between to two For..Next sets.


Guy Fawkes(Posted 2009) [#107]
um. yea. how come i cant choose my char. and why doesnt the block highlight. and why does characreate keep returning 1. and not changing to 0 when i use the mouseover?

code:

old_mouse_x = cur_mouse_x 
cur_mouse_x = MouseX() Shr 1
mouse_x_delta = cur_mouse_x-old_mouse_x
characreate = newchar
newchar = 0
newfinal = newchar
oldselect = newselect
newselect = 0
newsfinal = newselect

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next

DrawImage background, origx#, origy#

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If gfxw = 1600
DrawImage im, imx, imy-8, y*2+x
Else
DrawImage im, imx, imy, y*2+x
EndIf
Next
Next
	
For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
which = 2 * y + x
If (which = selected)
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next


what stupid typo did i do this time?

~DS~


Guy Fawkes(Posted 2009) [#108]
god i feel like an idiot. i accidently deleted "mh = mousehit(1)"
LOL

ok. now it wont draw ANY rect

i still cant get the rect to STAY ON the block when i click it, and when i select another block, delete the 1st rect, and move it to the 2nd block.

and when i select a block, if my mouse is down, then it STILL rotates the character even after i let go..

old_mouse_x = cur_mouse_x 
cur_mouse_x = MouseX() Shr 1
mouse_x_delta = cur_mouse_x-old_mouse_x
characreate = newchar
newchar = 0
newfinal = newchar
oldselect = newselect
newselect = 0
newsfinal = newselect
mh = MouseHit(1)

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth() Shr 1, GraphicsHeight() Shr 1
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

For x = 0 To 1
For y = 0 To maxblocks
imx = (0.2 * width) + (0.57 * width * x) + (origx#)
imy = (0.2 * height) + (0.1 * height * y) + (origy#)
If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
characreate = 1
Color 150,150,150
Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
EndIf
Next
Next



Flemmonk(Posted 2009) [#109]
Some of that I can read now that it is tabbed. I was getting a huge headache before, however now I dont understand what any variables mean, maybe you can comment some of them?


Guy Fawkes(Posted 2009) [#110]
yes. yes i will :)

ok. now it wont draw ANY rect

i still cant get the rect to STAY ON the block when i click it, and when i select another block, delete the 1st rect, and move it to the 2nd block.

and when i select a block, if my mouse is down, then it STILL rotates the character even after i let go..

old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX() Shr 1 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect
mh = MouseHit(1)

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth() Shr 1, GraphicsHeight() Shr 1
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf

For x = 0 To 1
    For y = 0 To maxblocks
     imx = (0.2 * width) + (0.57 * width * x) + (origx#)
     imy = (0.2 * height) + (0.1 * height * y) + (origy#)
       If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
         characreate = 1
         Color 150,150,150
           Rect imx-ImageWidth(im)/2, imy-ImageHeight(im)/2, ImageWidth(im), ImageHeight(im), 0
           Rect imx-ImageWidth(im)/2+1, imy-ImageHeight(im)/2+1, ImageWidth(im), ImageHeight(im), 0
        EndIf
    Next
Next



Guy Fawkes(Posted 2009) [#111]
i hope this helped you

~DS~


Guy Fawkes(Posted 2009) [#112]
if not, i can rewrite it

~DS~


Warner(Posted 2009) [#113]
If ImageRectOverlap(im, imx,imy, mx,my,1,1) And characreate = 0
characreate = 1
It will only respond if (characreate = 0). If that is so, it will immediately set (characreate) to one. So it will only be executed once, and after that, not again.

Replace it with lines that calculate "which" again, and then use an "if" to determine if "which" is "selected". You did write this code before, so you can just copy-paste if from a few version above.


Guy Fawkes(Posted 2009) [#114]
Rectangle problem:

solved.

ONE problem remaining.

when i select a character, even if my mouse isnt down, it still rotates my player.

code:

old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX()/2 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect

mh = MouseHit(1)

If characreate = 0
	If player1 <> 0
		If MouseDown(1)
			TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf
	
	If mx < 0 Then mx = 0
	If my < 0 Then my = 0
	If mx > GraphicsWidth() Then mx = GraphicsWidth()
	If my > GraphicsHeight() Then my = GraphicsHeight()

If KeyDown(29) <> KeyDown(57) Or KeyDown(57) <> KeyDown(29)

If KeyDown(29)
	MoveEntity cam, 0, .1, 0
Else If KeyDown(57)
MoveEntity cam, 0, -.1, 0
EndIf

EndIf

MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208) Or KeyDown(17) - KeyDown(31))*1
TurnEntity cam, 0, (KeyDown(203) - KeyDown(205) Or KeyDown(30) - KeyDown(32))*1, 0

UpdateWorld
RenderWorld

DrawImage background, origx#, origy#

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf


~DS~


Warner(Posted 2009) [#115]
Nice that the rects work now. To find out what is causing that, put a ; before any line that uses TurnEntity. If the problem goes away, enable these lines one by one to see which one is causing the problem.


Guy Fawkes(Posted 2009) [#116]
it appears mousedown(1) remains on

after i select my character.

how do i make that 0 ONLY after i select a character block and try to choose the same character twice ?

code:

old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX()/2 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect

mh = MouseHit(1)
omousedown = newmouse_down
newmouse_down = MouseDown(1)
fmousedown = newmouse_down

If characreate = 0
	If player1 <> 0
		If fmousedown
			;TurnEntity player1, 0, mouse_x_delta, 0
		EndIf
	EndIf
EndIf
	
	If mx < 0 Then mx = 0
	If my < 0 Then my = 0
	If mx > GraphicsWidth() Then mx = GraphicsWidth()
	If my > GraphicsHeight() Then my = GraphicsHeight()

If KeyDown(29) <> KeyDown(57) Or KeyDown(57) <> KeyDown(29)

If KeyDown(29)
	MoveEntity cam, 0, .1, 0
Else If KeyDown(57)
MoveEntity cam, 0, -.1, 0
EndIf

EndIf

MoveEntity cam, 0, 0, (KeyDown(200)-KeyDown(208) Or KeyDown(17) - KeyDown(31))*1
TurnEntity cam, 0, (KeyDown(203) - KeyDown(205) Or KeyDown(30) - KeyDown(32))*1, 0

UpdateWorld
RenderWorld

DrawImage background, origx#, origy#

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)
					HidePointer
				EndIf
			EndIf
		Next
	Next
EndIf


~DS~


Warner(Posted 2009) [#117]
Well, for instance take a variable that can be either 1 or 0. A flag. This flag can prevent the character from turning. Set the flag to 1 after a character is created.
Something along the lines of this:
if mousedown(1) and (mayturn = 1) then
  turn player
endif

if (selected new player) then mayturn = 0



Guy Fawkes(Posted 2009) [#118]
What am i doing wrong?


Global mayturn

old_mouse_x = cur_mouse_x ;this is the line where i define the old variable for mousex()
cur_mouse_x = MouseX()/2 ;this is the new mousex()
mouse_x_delta = cur_mouse_x-old_mouse_x ;this is the current mousex() ;this is what im going to use in the y value of "turnentity player1"
characreate = newchar ;this is the old characreate
newchar = 0 ;this is the new characreate
newfinal = newchar ;this is the value i will use to change characreate to 0 only if you are not mousing over a block.
oldselect = newselect
newselect = 0
newsfinal = newselect

mh = MouseHit(1)
omousedown = newmouse_down
newmouse_down = MouseDown(1)
fmousedown = newmouse_down

If player1 <> 0
	If fmousedown And mayturn = 0
	 mayturn = 1
		;TurnEntity player1, 0, mouse_x_delta, 0
	EndIf
EndIf

which=y*2+x

If (which) And mayturn = 1 Then mayturn = 0 : fmousedown = 0


PS: Just threw "global" in there to show u it can be used in the entire program.

~DS~


Guy Fawkes(Posted 2009) [#119]
did i explain good?

i can rewrite if u cant read.

np :)

~DS~


Warner(Posted 2009) [#120]
If (which) And mayturn = 1 Then mayturn = 0 : fmousedown = 0
What should this do? Basically, it is the same as this:
If (which <> 0) And mayturn = 1 Then mayturn = 0: fmousedown = 0


Guy Fawkes(Posted 2009) [#121]
it should turn off mousedown after a character is selected twice.


Guy Fawkes(Posted 2009) [#122]
which btw. is this:

If mh
	For x = 0 To 1
		For y = 0 To maxblocks
			imx = (0.2 * width) + (0.57 * width * x) + (origx#)
			imy = (0.2 * height) + (0.1 * height * y) + (origy#)
			If ImageRectOverlap(im, imx,imy,mx,my,1,1)
				which = y * 2 + x
				selected = which
				If player1 <> 0 And which <> oldwhich Then FreeEntity player1
				If which <> oldwhich Then
					player1 = loadmodel(which)
					If which = 0 Then ScaleEntity player1, .5,.5,.5 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, 0, 4
					If which = 1 Then  ScaleEntity player1, .15,.15,.15 : RotateEntity player1, 0, -180, 0 : PositionEntity player1, 0, -1.5, 8
					oldwhich = which
				Else If which = oldwhich
					MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
					ShowPointer
					MessageBox(SystemProperty("ApphWnd"), "Character already chosen!","Warning!", 0)

;TURN OFF MOUSEDOWN HERE!
					HidePointer
				EndIf
			EndIf
		Next
	Next



Guy Fawkes(Posted 2009) [#123]
did i explain good?

i can rewrite if u cant read.

~DS~


Guy Fawkes(Posted 2009) [#124]
I have tried EVERYTHING..

and though mayturn is 0,

mousedown is still 1..

~DS~


Flemmonk(Posted 2009) [#125]
Well, I can help answer that, however I will not write the code for you as I believe you will learn better reading a explanation on how to do it and discovering how to write the code yourself rather then copy and pasting my code.

There are 2 ways you could go about it:
1. Change your code so that you have a flag variable that you set to indicate that the player has chosen a character already. This way you can check when you detect a mouse hit, and compare if this flag variable is already set then to produce the message "character already chosen" thus preventing the rest of your code from been executed.

2. Alternatively you can look up the Blitz3D Help section under command reference and under "2D Category" view is a section called "User Input" this has all the commands you would ever need for user input and there is a command there that will clear the mouse buffer. However I dont think this way will help you.


Guy Fawkes(Posted 2009) [#126]
um. that doesnt help.

why?

because the ONLY way i know how to learn is by example of my own code...

~DS~


LineOf7s(Posted 2009) [#127]
If the only way you can bake a cake is by having someone else bake a cake and then give it to you, then perhaps baking is not for you.

At least TRY to maintain the illusion of trying. It's good for you. Seriously.


Ross C(Posted 2009) [#128]
Tbh DSW, this is the reason i don't help you, and probably a few others. Credit to warner for his extensive help on this, but, I am of the same view as lineof7's and Flemmonk. I generally don't have enough time to sit down and write out a whole example, to demonstrate my point. I could point you in the right direction in most of your questions, but i don't, because i know i'll have to provide a pretty extensive example. (Perhaps a fault in me?)

The only reason i mention this, is i don't want you to dwindle away those who put their free time into helping people. It really is great this board for helping folks out. I don't want to see you get stuck. And come a certain point your going to hit a wall, and your going to have to take ideas and turn them into code.

Best of luck to you, and i tip my hat to you Warner.


Guy Fawkes(Posted 2009) [#129]
hey! back OFF! i never said i wanted it done for me. i said that warner teaches the best outta all u. so u know what? just back off.

close this, do whateva mods..

im so sick and tired of people degrading me like this just because i learn twice as slow as all of u... :(


Warner(Posted 2009) [#130]
Thanks Ross for your good advice.
Dsw, about the mousedown problem. It might be caused by the messagebox. It takes the focus away from the bb window, leaving the mouse 'down'. Try removing the messagebox from the program.


Guy Fawkes(Posted 2009) [#131]
See ross? and lineof7s?

at least warner didnt degrade me..

so what if i learn twice as slow as all of you?

you have a PROBLEM w/ that?

and thanks to the way warner teaches, and no thanks to all of you, he has SOLVED this problem.. >:(

thanks again warner.

kudos to you! :)

~DS~


Flemmonk(Posted 2009) [#132]
Is that finally it then? CharaCreate complete?


Guy Fawkes(Posted 2009) [#133]
yes. characreate complete.


Ross C(Posted 2009) [#134]
Degrade you? Seriously... wtf you taking man. Blah blah blah ..back off.. blah blah. Do you actually READ what i was SAYING there?

Oh and DON'T worry. I WILL back off. I ain't posting in ANY of your topics again. (I think i capitalised the right words there.)


Guy Fawkes(Posted 2009) [#135]
fine! u know what?! i dont care anyway!


Guy Fawkes(Posted 2009) [#136]
and just for the record. we just had a gas leak, so yea. i dont care!


LineOf7s(Posted 2009) [#137]



Guy Fawkes(Posted 2009) [#138]
yea lineof7s. u be that way.

i could care less. im done.


Ginger Tea(Posted 2009) [#139]
and just for the record. we just had a gas leak, so yea. i dont care!


well that was random